您的位置:首页 > 其它

lightoj 1078 - Integer Divisibility 【同余】

2015-11-04 21:58 267 查看
1078 - Integer Divisibility



PDF (English)StatisticsForum
Time Limit: 2 second(s)Memory Limit: 32 MB
If an integer is not divisible by 2 or 5, some multiple of that number in decimal notation is a sequence of only a digit. Now you are given the number and the only allowable digit, you should report the number of digits of such multiple.

For example you have to find a multiple of 3 which contains only 1's. Then the result is 3 because is 111 (3-digit) divisible by 3. Similarly if you are finding some multiple of 7 which contains only 3's then, the result is 6, because 333333 is divisible
by 7.

Input

Input starts with an integer T (≤ 300), denoting the number of test cases.

Each case will contain two 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, print the case number and the number of digits of such multiple. If several solutions are there; report the minimum one.

Sample Input

Output for Sample Input

3

3 1

7 3

9901 1

Case 1: 3

Case 2: 6

Case 3: 12

 

PROBLEM SETTER: JANE ALAM JAN

题意:给定两个数n和d,问满足d...d % n == 0的所有十进制数中最小的数 含有多少个d。

简单题,中间会超long long,注意取余就好了。

AC代码:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN 500000+10
#define MAXM 50000000
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while(a--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define LL long long
using namespace std;
int main()
{
int t, kcase = 1;
Ri(t);
W(t)
{
LL n, d;
Rl(n); Rl(d);
LL ans = d;
LL cnt = 1;
for(;;)
{
ans %= n;
if(ans == 0)
break;
ans = ans * 10 + d;
cnt++;
}
printf("Case %d: %lld\n", kcase++, cnt);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: