yeah i had a lot of trouble debugging that part too
never mindā¦thanks anyways
yeah i had a lot of trouble debugging that part too
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)
Seriously, I donāt get whatās new in what you saidā¦we have been talking about it since the beginning. And i would really like you to find the ans for input ā2 100ā and you will realize what we have been talking about. Obviously long is not enough for the constraints.
damn! yes
After following up on discussion here, I did check out the private test case using accepted answers and if/else in my code, and turns out to be right! it was n1=2 and n2=100
Anyhow, I tried my python code again(you can check N run it out here if you want) and it gave me right ans in public test cases but failed in private test cases. I tried the accepted ones and found out this:
Python Fib list for 2,100 came as:
[9790, 19557, 29347, ā¦, 581249810872852619183037033064, 940481949946723723046417333531, 1521731760819576342229454366595]
whereas
Java/C++ Fib list for 2,100 came as:
[9790, 19557, 29347, ā¦, 4736557562071820904, -4020189681086890725, 716367880984930179]
Clearly the overflow was not taken into account by TCS geniuses and neither was mentioned anywhere in the question(or at least I couldnāt find any mention of it) and hence private testcase for this problem is kinda faulty. Well didnāt expect this at least! I mean How hard is it to correctly come up with some 6-8 questions in a year for TCS!
Why my ,Python Code isānt working , though my all test cases are workig well , but on TCS it is giving WA for private test casesā¦
## CODEVITA B ##
## Prime Fibo
n, m = map(int, input().split())
c = 0
l=[]
for i in range(n, m + 1):
for j in range(2, m + 1):
if i % j == 0:
c += 1
if c == 1:
l.append(i)
c = 0
continue
else:
c=0
continue
l_2 = []
for k in l:
for b in l:
if k!=b:
s=""
s=str(k)+str(b)
l_2.append(int(s))
l_2=list(set(l_2))
c_1=0
l_3 = []
for i in l_2:
for j in range(2,max(l_2)+1):
if i%j == 0:
c_1+=1
if c_1 == 1:
l_3.append(i)
c_1=0
else:
c_1=0
smallest = min(l_3)
largest = max(l_3)
su = 0
pre = smallest
aft = largest
for v in range(len(l_3)-2):
su = pre + aft
pre = aft
aft = su
print(su)
here is mine it passes all cases and Yes there is problem with python due lon long int limit;
indent preformatted text by 4 spaces
#include
#include
using namespace std;
long long int isPrime(long long int ans){
for(long long int i=2;i*i<=ans+1;i++){
if(ans%i==0){
return 0;
}
}
return 1;
}
int main() {
int a,b;
cin>>a>>b;
long long int a1[10000];
int sol=0;
for(int i=a;i<=b;i++){
if(isPrime(i)){
a1[sol]=i;
sol++;
}
}
set <int, greater <int> > s1;
long long int temp;
for(int i=0;i<sol;i++){
for(int j=0;j<sol;j++){
if(i!=j){
if(a1[j]<10){
temp=a1[i]*10+a1[j];
}
else{
temp=a1[i]*100+a1[j];
}
if(isPrime(temp)){
s1.insert(temp);
}
}
}
}
long int maxi=*s1.begin();
long int mini=*(s1.rbegin());
long long int t1,t2,c;
t1=mini;
t2=maxi;
c=t1+t2;
int lent=s1.size();
for(long int i=1;i<lent;i++){
t1=t2;
t2=c;
c=t1+t2;
}
cout<<t1<<endl;
}
Bro did you mail campus commune people about this issue.
I think many should mail them to get this issue recognized.
The email is
campuscommune@tcs.com
Take any accepted C++ solution and input range (2,100) and check the last few digits of fibonacci series. There you will find integer overflow.
In python there is no integer overflow so the answers for same code written in python and C++ are different for (2,100) and also I thingk that the test cases were made with C++. So C++ solution got accepted, while it gave wrong answer for the python.