Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Shows wrong Answer for Guessing Game problem

$
0
0

include <stdio.h>

int main () { int t,n,m; scanf ("%d",&t); for (int i = 0; i < t; i++) { scanf ("%d %d",&n,&m); int a,b,num,den; a = n % 2; if (a==0) { if (i==t-1) { printf("1/2"); continue; } printf("1/2\n"); continue; } b = m % 2; if (b==0) { if (i==t-1) { printf("1/2"); continue; } printf("1/2\n"); continue; } num = (nm-1)/2; den = (nm); if (i==t-1) { printf("%d/%d",num,den); continue; } printf("%d/%d\n",num,den); } return 0; }

I wrote the above code, i solved it mathematically and then came out to the conclusion that we do not need gcd for this question if we frame it like this. Anyone can help...?

Compile this in c++ 4.8.1 in ideone.com once and run the test cases, it gives correct answers.


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>