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.
Can anybody explain this: O(log(N * M)), complexity for the computation of gcd .
and this is O(1)
Could someone please tell me why my solution is wrong. Uncommenting the currently commented out section and deleting the code between the //----------------- result in a accepted solution, but funny thing is that the code between the
//------------- dashes are equivalent to the currently commented out section.
Here is my solution, sincerely thankful if someone would be kind enough to point out my mistake:
#include "stdio.h"
unsigned long long gcd(unsigned long long a, unsigned long long b){
unsigned long long r;
while(b){
r=a%b;
a=b;
b=r;
}
return a;
}
int main(){
unsigned long long t, n, m;
scanf("%llu", &t);
for(unsigned long long e=0;e<t;e++){
scanf("%llu", &n);
scanf("%llu", &m);
//-----------------
if((n%2)&&(m%2)){
unsigned long long d=gcd((n*m)-1,2*n*m);
printf("%llu", ((n*m)-1)/d);
printf("/%llu\n", (2*n*m)/d);
} else {
printf("%llu",1);
printf("/%llu\n",2);
}
//-----------------
//unsigned long long nodd=(n/2)+(n%2);
//unsigned long long neven=(n/2);
//unsigned long long modd=(m/2)+(m%2);
//unsigned long long meven=(m/2);
//unsigned long long num=(nodd*meven)+(modd*neven);
//unsigned long long den=n*m;
//unsigned long long d=gcd(num, den);
//printf("%llu", num/d);
//printf("/%llu\n", den/d);
//}
}
http://www.codechef.com/viewsolution/4313343
I keep getting WA with this Any idea what mistake i am making??
I am getting WAā¦whats wrong with my codeā¦pls reply meā¦
willnt case 1 and case 4 interchange ā¦??