水题。
给你初始时间s,d。则算一次时间为( s + d*s )%60.问你最少算多少次可以到达0.
直接循环就好。算一次s在数组中标记下,如果s第二次遇到, 说明有环了,永远达不到了。。
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string.h>
#include <queue>
#include <limits.h>
using namespace std;
int Clock[60];
int main()
{
int s,d,flag,cnt;
long long M;
while( ~scanf("%d%d",&s,&d) && d )
{
memset(Clock,0,sizeof(Clock));
Clock[s] = 1;
flag = cnt = 0;
while( s != 0 )
{
s = (s*d+s)%60;
cnt++;
if( Clock[s] == 1 )
{
flag = 1;
break;
}
Clock[s] = 1;
}
if( flag == 1 )
printf("Impossible/n");
else
printf("%d/n",cnt);
}
return 0;
}