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

时间:2020-11-29 12:46:08

Problem Descripton

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(0≤N), 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

Sample Output
Case #: YES
Case #: YES
Case #: NO

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5832

***********************************************************

题意:嘻嘻和哈哈两个星球分别以73和137为一年的周期,给你天数,判断是否是两个星球的新一年第一天。

分析:周期嘛:10001就是73和137的最小公倍数。然后输入的是字符串,注意给的范围是字符串的长度不是数的大小,所以用到大数求余,仅此而已。

AC代码:

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <vector>
using namespace std; #define N 12000000
#define INF 0x3f3f3f3f char s[N]; int main()
{
int k=,len,x,d,i; while(scanf("%s", s) != EOF)
{
k++;
len = strlen(s); x=;
d=; for(i=;i<len;i++)
d=(d*+(s[i]-'')%x)%x; if(d==)
printf("Case #%d: YES\n",k);
else
printf("Case #%d: NO\n",k);
}
return ;
}