Mockvita 1 2020 Problem B - Prime Fibonacci

Okk @bal_95 , its my mistake I didn’t deep dive into your code and just look into

import permutation

but still I was just trying to make it sense to you and nothing more than that. In my solution (which passed the public and private testcase) I simply followed these following steps:

  1. loop from n1 to n2 and put all the primes into a separate list say p1.
  2. used a O(n^2) loop to form all the combinations required and at the same time checked whether the combination is a prime number or not? If yes, put into another prime list say p2
  3. find out the minimum and maximum out of list p2
  4. used them as a and b of fibonacci series and find the kth element where k is the size of p2.

Is there any way to see our submissions, coz I wanna post my solution. It may help others?

I also did exact same thing as the question is straight forward, but in Python. Don’t know why got Wrong answer in private test cases.

almost what i did in the code…nothing extra. Your is way more clear, mine a little too complex :slight_smile:

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