A water problem HDU - 5832(大数)(2016中国大学生程序设计竞赛 - 网络选拔赛)

 Two planets named Haha and Xixi in the universe and they were created with the universe beginning. 

 There is 73 days in Xixi a year and 137 days in Haha a year. 

 Now you know the days N after Big Bang, you need to answer whether it is the first day in a year about the two planets.

 

 

Input

 There are several test cases(about 5 huge test cases). 

 For each test, we have a line with an only integer N(0N), the length of N is up to 10000000.

 

Output

 For the i-th test case, output Case #i: , then output "YES" or "NO" for the answer.

 

Sample Input

10001
0
333

Sample Output

Case #1: YES
Case #2: YES
Case #3: NO

题意:

若输入数字能整除73和137,输出YES;否则NO

输入数字位数上限为1e7

 

思路:

单看数据范围就知道一定要用字符串操作,大数相除,模拟除法运算过程即可

 1 #include <stdio.h>
 2 #include <string.h>
 3 
 4 char a[10000005];
 5 
 6 int main()
 7 {
 8     int i, len, flag1, flag2;
 9     int x = 73, y = 137, t;
10     int cas = 0;
11 
12     while(~scanf("%s", a))
13     {
14         len = strlen(a);
15         t = 0;
16         flag1 = 0;
17         flag2 = 0;
18 
19         for(i = 0; i < len; i++)
20         {
21             t = (t * 10 + a[i] - '0') % x;
22         }
23         if(t==0) flag1 = 1;
24 
25         t = 0;
26         for(i = 0; i < len; i++)
27         {
28             t = (t * 10 + a[i] - '0') % y;
29         }
30         if(t==0) flag2 = 1;
31 
32         if(flag1 && flag2) printf("Case #%d: YES\n", ++cas);
33         else printf("Case #%d: NO\n", ++cas);
34     }
35     return 0;
36 }

 

posted @ 2019-08-17 19:54  Xxiaoyu  阅读(109)  评论(0编辑  收藏  举报