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

Junjie Liang Can someone give me a test case where my program fails? [4] // Problem 1023. Buttons 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;
}
Ivan Georgiev Re: Can someone give me a test case where my program fails? [3] // Problem 1023. Buttons 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.
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;
}
Ivan Georgiev Re: [1] // Problem 1023. Buttons 13 Feb 2002 22:15
Yes it is.
You give answer 1 to input 4 again.
Junjie Liang Silly me! Anyone I have AC now...THANKS! (-) // Problem 1023. Buttons 14 Feb 2002 14:54