|
|
back to boardCan someone give me a test case where my program fails? #include <stdio.h> long min, num, i; int main() { scanf("%ld", &num); min = num - 1; if (num % 2 == 0) min = (num / 2) - 1; for (i = 3; i*i <= num; i++) if (num % i == 0) if ((i-1) < min) { min = i-1; break; } printf("%ld\n", min); return 0; } Re: Can someone give me a test case where my program fails? There is a restriction -- the answer is >= 2; so for example the answer for 4 is 3 (not 1); Good luck. Re: Can someone give me a test case where my program fails? Thanks, but I still get WA. Is this revised copy wrong as well? #include <stdio.h> long min, num, i; int main() { scanf("%ld", &num); min = num - 1; if (num == 4) { min = 3; } if (num % 2 == 0) min = (num / 2) - 1; for (i = 3; i*i <= num; i++) if (num % i == 0) if ((i-1) < min) { min = i-1; break; } printf("%ld\n", min); return 0; } Re: Yes it is. You give answer 1 to input 4 again. Silly me! Anyone I have AC now...THANKS! (-) |
|
|