hdu 1393

来源:互联网 发布:pdf拼接软件 编辑:程序博客网 时间:2024/06/05 07:53

Weird Clock

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1747    Accepted Submission(s): 632


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
 

Author
DU, Peng
 

Source
ZOJ Monthly, December 2002
 

Recommend
Ignatius.L
 
#include <stdio.h>int main(){int s, d, i;while (scanf("%d%d", &s, &d)){if(s==0 && d==0)break;i = 0;while (s%60){i++;if(i == 60)break;s += s*d;//d times clockwise the current timeif (s > 60)s %= 60;// s is the current time}if (i == 60){printf("Impossible\n");}elseprintf("%d\n", i);}return 0;}

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 体温计打碎了水银找不到了怎么办 模拟城市5核电站爆炸怎么办 日本地铁票丢了怎么办 在日本地铁票丢了怎么办 首付交了没合同怎么办 工程干完不给签合同怎么办 寄存密码纸丢了怎么办 超市柜子纸丢了怎么办 楼下有污水井味道怎么办 孕妇闻到了烧垃圾怎么办 楼下9米垃圾房怎么办 在工厂上班得了职业病怎么办 自来水被农药水污染了怎么办 雾霾天头疼恶心怎么办? 夫妻住宾馆一个没有身份证怎么办 医保报销后认定工伤怎么办 结肠癌术后复查有息肉怎么办 无蒂息肉恶变要怎么办 贤者时间很长怎么办 鸡吃了酒米醉了怎么办 自填脂肪乳房脂肪液化怎么办 中国人在外国遇到危险怎么办 dnf刷图卡住了怎么办 dbf深渊怪卡住了怎么办 dnf86级没任务了怎么办 dnf二觉任务没了怎么办 脚趾甲变空向上翘怎么办 汽油车加了一点柴油怎么办 柴油车辆环保检测功率不足怎么办 加95加错一次92怎么办 新车95加错92油怎么办 加不到95号汽油怎么办 去新疆没95号油怎么办 黄龙300加了92怎么办 gla错加92号油 怎么办 95和98混加了怎么办 沥青车可以停在居民区怎么办 汽油进到眼睛了怎么办 汽油进了眼睛里怎么办 眼睛里面进了汽油怎么办 脱硫塔里的二氧化硫高怎么办