Time Limit: 2000MS | Memory Limit: 32768KB | 64bit IO Format: %lld & %llu |
Description
If an integer is notdivisible by 2 or 5, some multiple of that number in decimal notation is asequence of only a digit. Now you are given the number and the only allowabledigit, you should report the number of digits of such multiple.
For example you have tofind a multiple of 3 which contains only 1's. Then the result is 3 because is111 (3-digit) divisible by 3. Similarly if you are finding some multiple of 7which contains only 3's then, the result is 6, because 333333 is divisible by7.
Input
Input starts with aninteger T (≤ 300), denotingthe number of test cases.
Each case will containtwo integers n (0 < n ≤ 106 and n will not be divisible by 2 or 5) and the allowable digit (1 ≤ digit ≤ 9).
Output
For each case, printthe case number and the number of digits of such multiple. If several solutionsare there; report the minimum one.
Sample Input
3
31
73
99011
Sample Output
Case1: 3
Case2: 6
Case3: 12
Source
ProblemSetter: Jane Alam Jan
题意:
给定一个不能够被 2 和 5 整除的数字 n ,再给定一个数字 dight 问至少要有几个后者组成的数字能够被前者整除。
例如,测试数据:
3 1>>3;
111%3=0;
思路:
之前在宇神博客看过这个题目,只是扫一眼而已。
没想到同余定理,也是够了。做题少,总结不够。
代码:
#include<stdio.h>
int main() {
int t;
scanf("%d",&t);
int v=1;
while(t--) {
int n,dight;
scanf("%d%d",&n,&dight);
int pro=dight%n;//记录累乘之后的余数
int ans=1;//记录答案
while(pro) {
pro=dight+pro*10;//这个公式竟然一次没写出来
pro%=n;
ans++;
}
printf("Case %d: %d\n",v++,ans);
}
return 0;
}
#include<stdio.h>
*******************************************************************************************************************************************************************