Yeah…it was just because of not using long long int. Thanks
same solution when i am executing it is showing AC check this link CodeChef: Practical coding for everyone
you have used too many loops i think you will get TLE …try to use pen and paper … just a little thinking and boom you will get the answer or try to follow editorial note…
i think there is little problem in logic
try to replace “num=(2nm) + m -n;” with “num=(2nm) + m + n;” in your code and then try again.
how could You say answer will be (floor(N / 2) * ceiling(N / 2)) / (N * M) ???
for n=10 and m=10 answer is 1/4 while correct answer is 1/2.
you haven’t use return 0 cause your return type is int.
put return 0 and try.
and this is O(1)
willnt case 1 and case 4 interchange …??
Very Nice Explanation, Thank you.
#include<bits/stdc++.h>
#include<string.h>
#define ll long long
using namespace std;
int main()
{
int t=1;
cin>>t;
while(t--)
{
ll int n,m;
cin>>n>>m;
ll int a=n/2;
ll int b=(n+1)/2;
ll int gcd=__gcd(a*b,n*m);
cout<<(a*b)/gcd<<"/"<<(m*n)/gcd<<endl;
}
return 0;
}
what is error in this
You have not taken all possible cases into account. The sum of the 2 numbers chosen by Alice and Bob can be odd only in 2 cases :
- When Alice chooses an odd number and Bob chooses an even number
- When Alice chooses an even number and Bob chooses an odd number
Since Alice has total n choices and Bob has total m choices, the answer will be -
P(OA)*P(EB) + P(EA)*P(EB) where,
P(OA) = Probability of Alice choosing an Odd Number = (n+1)/2
P(EB) = Probability of Bob choosing an Even Number = (m/2)
P(EA) = Probability of Alice choosing an Even Number = (n/2)
P(OB) = Probability of Bob choosing an Odd Number = (m+1)/2
You can also refer to your modified solution here
Thank you very very much.
I clearly understood from your very nice explanation.