Training 1 - E题
Two planets named Haha and Xixi in the universe and they were created with the universe beginning.
There is 7373 days in Xixi a year and 137137 days in Haha a year.
Now you know the days NN 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 55 huge test cases).
For each test, we have a line with an only integer N(0≤N)N(0≤N), the length of NN is up to 1000000010000000.
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
#pragma warning (disable:4996)
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <queue>
#define inf 0X7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e7 + 5;
const int M = 9;//状压
char str[maxn];
int main()
{
int cas = 0;
while (scanf("%s", str) != EOF)
{
int tmp = 0;//不会超1e6
for (int i = 0; i < strlen(str); i++)
tmp = (tmp * 10 + str[i] - '0') % 10001;
if (tmp == 0)
printf("Case #%d: YES\n", ++cas);
else
printf("Case #%d: NO\n", ++cas);
}
return 0;
}
思路:
输入的数设为x,如果满足 x % 73 == 0 && x % 137 == 0,由于73和137的最小公倍数是73 * 137 = 10001,条件即为x % 10001 == 0,答案输出yes;反之输出no。
大数的取模运算,可以用str[i]-'0’表示第i位的数字a[i],x = Σ a[i] * 10 ^(i-1),又因为(a + b) % m == a % m + b % m, 可以把a[i]的取模结果累加得到x的取模结果。