lightoj 1078 - Integer Divisibility 【同余】
2015-11-04 21:58
267 查看
1078 - Integer Divisibility
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.
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).
PROBLEM SETTER: JANE ALAM JAN
题意:给定两个数n和d,问满足d...d % n == 0的所有十进制数中最小的数 含有多少个d。
简单题,中间会超long long,注意取余就好了。
AC代码:
PDF (English) | Statistics | Forum |
Time Limit: 2 second(s) | Memory Limit: 32 MB |
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; }
相关文章推荐
- lightoj 1020 - A Childhood Game 【博弈】
- 数据的插入、更新、删除
- C++11新特性之 CALLBACKS
- 知名公司的Java面试题
- Set,List,Map,Vector,ArrayList的区别
- eclipse 更改默认java风格
- NOIP提高组 2015.11.04总结
- SQL语句操作数据与一些函数使用的丰富数据库
- sql保存
- FOJ 1962 新击鼓传花游戏 线段树
- Add Two Numbers
- 次小生成树模版(MST)
- td和div超出部分隐藏的区别和用法
- 比较好的前端开发工具
- lightoj 1010 - Knights in Chessboard 【数学思维】
- 2015年MyEclipse使用教程最强盘点
- 【HNOI2014】【BZOJ3573】米特运输
- lightoj 1008 - Fibsieve`s Fantabulous Birthday 【数学 找规律】
- 一些关于git的基本使用方法
- 点9图片的处理