Mockvita 1 2020 Problem B - Prime Fibonacci

Not possible. I think.

anyone who solved problem D? , I was getting a slight difference in calculated revenue also in the problem when number of patients are greater than total number of rooms was not defined.

@shivam_js
For problem D take into account the following observations:

For the year:-
Before august-
odd months have 31 days and even months have 30 days except February it has 28 days(non-leap year).

August onwards-
odd months have 30 days and even months have 31 days.

For calculating revenue for each day:-
There are 3 conditions
if(no. of patients > = no. of rooms) //all rooms will be accquired
revenue+=(no. of tv rooms * cost of tv rooms) + (no. of non-tv rooms * cost of non-tv rooms)

else if(no. of patients < no. of rooms && no. of patients <= no. of non-tv rooms)
//in this the patients will acquire only non-tv rooms
revenue+=(no. of patients * cost of non-tv rooms)

else if(no. of patients < no of rooms && no. of patients > no. of non-tv rooms)
//in this all non-tv rooms will be acquired and remaining patients will acquire tv rooms
//remaining patients=no. of patients - no. of non-tv rooms
revenue+=(no. of non-tv rooms * cost of non-tv rooms) + (remaining patients * cost of tv rooms)

@akashdileep Can you please review this function i made to calculate the revenue

def check(tvrooms,totalrooms,r1,r2):
    revenue=0
    month=[31,28,31,30,31,30,31,31,30,31,30,31]
    nontvrooms=totalrooms-tvrooms
    for i in range(1,13):
        for j in range(1,month[i-1]+1):
            people=((6-i)**2)+abs(j-15)
            print(tvrooms,nontvrooms)
            if people>=totalrooms:
                revenue+=(tvrooms*r1)+(nontvrooms*r2)
            else:
                if people<=nontvrooms:
                    revenue+=nontvrooms*r2
                else:
                    revenue+=((people-nontvrooms)*r1)+(nontvrooms*r2)
    return revenue

cases = int(input())
for i in range(1, cases + 1):
value = int(input())
coincount = 0
while value >= 1:
value = value // 2
coincount = coincount + 1
print(coincount)

i am sorry

So, there are no fault with the test cases

Lol only if you looked at the SS above, which says n2-n1 >= 35 clearly.

Same bro!

yah i reconsidered it. there were actually lot of problem with the test cases of tcs actually

1 Like

like the test cases of 3rd problem was also unprecedented

@shivam_js

else:
         if people<=nontvrooms:
                revenue+=people*r2

//Because no. of people can be less than no. of non-tv rooms
//revenue+=nontvrooms*r2 (This should occur when -> no. of people == no. of non-tv rooms)

1 Like

I did what was exactly asked in the question and I got AC.

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf long double
#define vi vector<int>
#define vl vector<long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define in insert
#define all(x) x.begin(),x.end()
#define zapp ios::sync_with_stdio(false);cin.tie(0)
const int MAXN = 1e4 + 5;

vector<bool> prime(MAXN, true);

void sieve()
{
	prime[0] = prime[1] = false;
	int i, j;
	for (i = 2; i * i < MAXN; i++)
	{
		if (prime[i])
		{
			for (j = i * i; j <= MAXN; j += i)
				prime[j] = false;
		}
	}
}


int main()
{
	zapp;
	sieve();
	ll n1, n2;
	cin >> n1 >> n2;
	ll i, j = 0;
	vector<string> bet;
	for (i = n1; i <= n2; i++)
	{
		if (prime[i])
			bet.pb(to_string(i));
	}

	vector<ll> nums;
	ll n = bet.size();
	for (i = 0; i < n; i++)
	{
		for (j = i + 1; j < n; j++)
		{
			string s = "";
			s += bet[i];
			s += bet[j];
			stringstream geek(s);
			ll x = 0;
			geek >> x;
			nums.pb(x);
			string v = "";
			v += bet[j];
			v += bet[i];
			stringstream meek(v);
			ll y = 0;
			meek >> y;
			nums.pb(y);
		}
	}

	sort(nums.begin(), nums.end());
	set<ll> prm;

	ll m = nums.size();
	for (i = 0; i < m; i++)
	{
		if (prime[nums[i]])
			prm.in(nums[i]);
	}

	ll cnt = prm.size();
	vl act;
	for (auto x : prm)
		act.pb(x);

	ll a = act[0];
	ll b = act[cnt - 1];
	ll fib[cnt];
	fib[0] = a;
	fib[1] = b;
	for (i = 2; i < cnt; i++)
	{
		fib[i] = fib[i - 1] + fib[i - 2];
	}

	cout << fib[cnt - 1];


	return 0;
}


If anyone here was able to solve E - Question, kindly share your approach :slight_smile:

if by E you mean lazy student then probability=1 (if number of unknowns n-m <number of questions in test paper t) or 1-[(n-m)Ct / nCt]

could you solve F btw? if yes…do share your approach

Damn, I used the same formula but then maybe fucked up in the nCr part. :frowning:

No man, I couldn’t implement it properly. It had something to do with the points’ images on the x-axis, but couldn’t figure it out.

1 Like

yeah i had a lot of trouble debugging that part too :sweat_smile: :sweat_smile: :sweat_smile:

never mind…thanks anyways

My solution for E. Please debug it. Thanks

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define lf long double
#define vi vector<int>
#define vl vector<long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define in insert
#define all(x) x.begin(),x.end()
#define zapp ios::sync_with_stdio(false);cin.tie(0)

ll add(ll x, ll y) {ll res = x + y; return (res >= MOD ? res - MOD : res);}
ll mul(ll x, ll y) {ll res = x * y; return (res >= MOD ? res % MOD : res);}
ll sub(ll x, ll y) {ll res = x - y; return (res < 0 ? res + MOD : res);}
ll power(ll x, ll y) {if (y < 0) return 1; ll res = 1; x %= MOD; while (y) {if (y & 1)res = mul(res, x); y >>= 1; x = mul(x, x);} return res;}
ll inv(ll x) {return power(x, MOD - 2);}

const ll mx = 1005;

ll fac[mx + 1];

void pre()
{
	fac[0] = 1;
	for (ll i = 1 ; i <= mx; i++)
		fac[i] = fac[i - 1] * i % MOD;
}

ll nCr(ll n, ll r)
{
	if (r == 0)
		return 1;
	return (fac[n] * inv(fac[r]) % MOD * inv(fac[n - r]) % MOD) % MOD;
}

int main()
{
	pre();
	ll t;
	cin >> t;
	while (t--)
	{
		ll n, b, m;
		cin >> n >> b >> m;
		ll q = nCr(n, b);
		ll p;

		if (m + b > n)
			p = q;
		else
			p = nCr(n, b) - nCr(n - m, b);

		ll g = __gcd(p, q);
		p = p / g;
		q = q / g;

		cout << p*inv(q) << "\n";

	}

	return 0;
}


def fib(a,b,n):

sum=0

if n==1:

    return a

elif n==2:

    return b

else:

    for i in range(n-2):

        sum=a+b

        a=b

        b=sum

    return sum

def cprim(a):

count=0

for i in range(1,a+1):

    if a%i==0:

        count+=1

if count==2:

    return 1

else:

    return 0

def ran(a,b):

li=[]

for i in range(a,b+1):

    if(cprim(i)==1):

        li.append(str(i))

return li

def merg(a):

nli=[]

for i in range(len(a)):

    for j in range(len(a)):

        if(i!=j):

            b=int(a[i]+a[j])

            if b not in nli:

                nli.append(b)

nli.sort()

return nli

a,b=[int(x) for x in input().split()]

s1=ran(a,b)

s2=merg(s1)

s3=[]

for i in range(len(s2)):

if(cprim(s2[i])==1):

    s3.append(s2[i])

ans=fib(s3[0],s3[-1],len(s3))

print(ans)

@anon18036669 thank you so much