light oj 1078 - Integer Divisibility【同余定理】
2015-12-03 17:56
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 andn will not be divisible by
2 or 5) and the allowable digit(1 ≤ digit ≤ 9).
![]() | 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 andn 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 |
#include<cstdio> #include<cstring> int main(){ int T,t; scanf("%d", &T); for(t = 1; t <= T; t++){ int n,d,a; scanf("%d%d", &n, &d); a = d%n; int cnt = 1; while(a) { a = (a*10+d)%n;//放在while位置 超时。。 cnt++; } printf("Case %d: %d\n", t, cnt); } return 0; }
相关文章推荐
- 反射(二)---newInstance、get\set、invoke
- Maven+Spring+Spring MVC+MyBatis+MySQL,搭建SSM框架环境
- 杭电1081 暴力dp 最大子矩阵和
- mysql 主重复制过程
- [转]响应式表格jQuery插件 – Responsive tables
- [原译]在mongoose中对Array Schema进行增删改
- 什么是性能?
- Linux安装jdk
- android-Menu Resource
- 实习整理(十七)
- 反射(一)---类Class
- DIV常用边框样式css
- HLG2003 棋盘
- 哈理工1004 数塔
- 超级密码(dfs)
- Linux网络编程TCP之并发服务
- 【django】Nginx+uWSGI+Django部署我的博客网站
- 使用Java编写并运行Spark应用程序
- selenium自动化测试实现对网站的登陆(使用java编写)
- 易错知识点