HDU 1393 Weird Clock

来源:互联网 发布:淘宝上比较好的女鞋店 编辑:程序博客网 时间:2024/05/23 23:58

Weird Clock

Problem Description
A weird clock marked from 0 to 59 has only a minute hand. It won't move until a special coin is thrown into its box. There are different kinds of coins as your options. However once you make your choice, you cannot use any other kind. There are infinite number of coins of each kind, each marked with a number d ( 1 <= d <= 1000 ), meaning that this coin will make the minute hand move d times clockwise the current time. For example, if the current time is 45, and d = 2. Then the minute hand will move clockwise 90 minutes and will be pointing to 15.

Now you are given the initial time s ( 1 <= s <= 59 ) and the coin's type d. Write a program to find the minimum number 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 10 0
 
Sample Output
1

题意:有一个只有分针的表,给出针的初始位置,然后后面是倍数n,每次顺时针旋转当前点数的n倍,最后求转到0需要多少步。如果转不回去就输出Impossible。

直接就照他的走,反正步数不会太多,顶多60步,转到初始位置说明是个死循环,则不可能。

#include<stdio.h>int main(){    int n,d,i,j,N;    while(~scanf("%d%d",&n,&d)&&n+d)    {        N=n;        j=0;        for(i=0; i<60; i++)        {            if(n==0)            {                printf("%d\n",j);                break;            }            j++;            n+=n*d;            n=n%60;        }        if(n!=0)        {            printf("Impossible\n");        }    }    return 0;}


2 0