can anybody tell on which cases my solution is failing
http://www.codechef.com/IOPC2014/problems/IOPC14A/
my code is
thnx…
can anybody tell on which cases my solution is failing
http://www.codechef.com/IOPC2014/problems/IOPC14A/
my code is
thnx…
The basic problem with the code which I get is that the you haven’t taken the case when “re” variable of yours exceeds the value of its range of long long int i.e. as b is of the order of 10^18 and you are multiplying re variable by i which if of the order of 10^5. It is sure to exceed its limit sometime for higher values. Hence that needs to be handled.
Take as test case:
1
100000 1000000000000000000
and print re’s value by using a slight modification to your code:
#include <iostream>
#include <algorithm>
#define ll long long int
using namespace std;
int main()
{
int t;
cin>>t;
while(t--)
{
ll i,j,k,l,m,n,b,odd=0,re=1;
cin>>n>>b;
for(i=0;i<=n;i++)
{
if(i==0)
re=1;
else
re*=i;
cout<<re<<endl;
if(re>=b)
{
ll temp;
temp=re/b;
re=re%b;
if(temp%2==1)
{
if(i!=n)
{
if(i%2==0&&(i+2)>n)
{
odd++;
}
}
else if(i==n)
{
odd++;
}
}
}
}
if(odd%2==0)
{
cout<<"Even\n";
}
else
{
cout<<"Odd\n";
}
}
return 0;
}
You can see that something is wrong with re’s value.
Oh completely forgot to check the overflow …thanx for help …got it was required to use modular multiplucation…