Problem Description
F(x,m)代表一个全是由数字x组成的m位数字。请计算,以下式子是否成立:
F(x,m) mod k = c
Input
第一行一个整数TT,表示TT组数据。 每组测试数据占一行,包含四个数字x, m, k, c
1 ≤ x 91 ≤ 9
1 ≤ m ≤ 1010
0 ≤ c< k ≤ 10
Output
对于每组数据,输出两行: 第一行输出:"Case #i:"。ii代表第ii组测试数据。 第二行输出“Yes” 或者 “No”,代表四个数字,是否能够满足题目中给的公式。
Sample Input
3
1 3 5 2
1 3 5 1
3 5 99 69
Sample Output
Case #1:
No
Case #2:
Yes
Case #3:
Yes
测试代码
1 #include <stdio.h>
2
3 int main()
4 {
5 int t, iCase = 0;
6 scanf("%d", &t);
7 while (t--)
8 {
9 iCase++;
10 long long int x, m, k, c;
11 scanf("%I64d%I64d%I64d%I64d", &x, &m, &k, &c);
12 m %= k;
13 long long int re = 0;
14 for (int i = 1; i <= m; i++)
15 {
16 re = (re * 10 + x) % k;
17 }
18 re %= k;
19 printf("Case #%d:\n", iCase);
20 if (re == c)
21 {
22 printf("Yes\n");
23 }
24 else
25 {
26 printf("No\n");
27 }
28 }
29 return 0;
30 }