Weird Clock time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 1771 accepted submission (s): 643
Problem Description a weird clock marked from 0 to the has only a minute hand. It won ' t move until a special coin are thrown into its box. There are different kinds of coins as your options. However Once you do your choice, you cannot use the any other kind. There are infinite number of coins of each kind, all marked with a number D (1 <= d <= 1000), meaning so this C Oin'll make the minute hand the "D times clockwise the" times. For example, if it is, and d = 2. Then the minute hand'll move clockwise the minutes and would be pointing to 15.
Now, are given the initial time S (1 <= s <=) and the coin ' s type D. Write a program to find the minimum num ber of D-coins needed to turn the minute hand back to 0.
Input There are several tests. Each test occupies a line containing two positive integers s and d.
The input is finished by a line containing 0 0.
Output for each test print in a single line the minimum number of coins needed. If It is impossible to turn the hand back to 0, output "impossible".
Sample Input
30 1 0 0
Sample Output
1
————————————————————————————————————————————————————————
Consider the failure to meet the requirements of the problem, that is, the output "impossible" condition is when the recurrence of the previous occurrence of the time is not able to meet the requirements, I set a length of 60 of the array record whether the current time has occurred.
/****************************
*name:weird clock.c
*tags:acm water
*note: When the second occurrence of the same result is not possible to achieve the problem requirements, Output Impossible
****************************/
#include <stdio.h>
int main ()
{
int s, D, T, SAVE[60], I;
while (scanf ("%d%d", &s, &d)!= EOF && (S. | d)) {for
(i = 0; i <; i++) {
save[i] = 0;
}
if (d = = 0 && s) {
printf ("impossible\n");
Continue;
}
t = 0;
while (s!= 0 &&!save[s]) {
Save[s] = 1;
s = (S * (d + 1))%;
t++;
}
if (s = = 0) {
printf ("%d\n", t);
} else {
printf ("impossible\n");}
}
return 0;
}