ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1023. Buttons

Can someone give me a test case where my program fails?
Posted by Junjie Liang 11 Feb 2002 20:45
#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?
Posted by Ivan Georgiev 11 Feb 2002 21:25
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?
Posted by Junjie Liang 13 Feb 2002 08:13
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:
Posted by Ivan Georgiev 13 Feb 2002 22:15
Yes it is.
You give answer 1 to input 4 again.
Silly me! Anyone I have AC now...THANKS! (-)
Posted by Junjie Liang 14 Feb 2002 14:54