题目:

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 (10的6次方)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

3

3 1

7 3

9901 1

Sample Output

Case 1: 3

Case 2: 6

Case 3: 12

代码:

#include <iostream>
using namespace std;
int main()
{long long t,n,i,ans,m,tem;cin>>t;ans=1;while(t--){cin>>m>>n;cout<<"Case "<<ans++<<": ";if(n%m==0){cout<<"1"<<endl;continue;}tem=n;for(i=1;n!=0;i++){n=(n*10+tem)%m;}cout<<i<<endl;}return 0;
}

LightOJ 1078 Integer Divisibility (同余定理)相关推荐

  1. LightOj 1078 Basic Math

    思路: 设输入的两个数分别为n和a,每一次所得到的数为update: 开始update=a,依次update分别为update*10+a,这样数据会超出范围,则update每次为update=(upd ...

  2. Light oj 1214-Large Division (同余定理)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1214 题意很好懂,同余定理的运用,要是A数被B数整除,那么A%B等于0.而A很大,那我 ...

  3. Codeforces数学1600----day1[同余定理,树状数组+两次二分,,组合计数]

    1.C. Kuroni and Impossible Calculation **知识点:同余定理 ** #include <iostream> #include <cstdio&g ...

  4. CSDN 厦门大学线下编程比赛第一题:求和(同余定理)

    题目意思: 给定a和n,计算a+aa+aaa+aaaa+...+a...a(n个a) 的和. 输入描写叙述:測试数据有多组,以文件结尾.每行输入a,n(1<=a,n<=1000000). ...

  5. 十二届 - CSU 1803 :2016(同余定理)

    题目地址:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1803 Knowledge Point: 同余定理:两个整数a.b,若它们除以整数m所 ...

  6. 同余定理在算法求解中的应用

    1. 同余定理 (a−b)modK=0⇓(amodK)=(bmodK) (a-b)\mod K=0\\ \Downarrow\\ \left(a\mod K\right) = \left(b\mod ...

  7. Divisible [数学]同余定理

    给定一个很大的整数,我想知道它能否被9整除. 输入 有t组测试数据,每组数据给定一个整数N不存在前导0.(1 <= t <= 20,1 <= N <= 10^200). 输出 ...

  8. 同余定理+前缀和解题技巧

    相关题目 和可被 K 整除的子数组 连续的子数组和 Delete Sublist to Make Sum Divisible By K 思路 前缀和就不单独说了,同余定理贴一个百度百科 同余定理 数论 ...

  9. 同余定理在计算机科学的应用,同余定理在小学数学竞赛中的应用

    肖丽 [摘要]本研究基于高观点视角,例析同余定理在小学数学竞赛中的应用,探讨运用其解决小学奥数问题的优越性. [关键词]小学数学竞赛 同余定理 应用 [中图分类号]G623.5[文献标识码]A [文章 ...

最新文章

  1. input 默认样式的修改
  2. 卫星对于物联网来说是一个非常好的选择
  3. 论字符界面和WEB界面配置的优缺点
  4. TCP/IP之传输层(一)
  5. Nervos 双周报第 3 期:佛系新年之后的开工大吉!
  6. linux epoll监听套接字实例
  7. 2016年第七届蓝桥杯C/C++ A组国赛 —— 第三题:打靶
  8. 一个跨平台的 C++ 内存泄漏检测器
  9. Cloudera完善企业数据云愿景,新品进一步扩展无处不在的云体验
  10. CSV文件的转义处理
  11. Adaptive Execution patch and how to bulid on cdh5
  12. matlab 和 ampl 结合,AMPL和MATLAB结合使用示例
  13. 肖维勒准则matlab_肖维勒准则.PPT
  14. Web程序设计(第三版)课后习题答案
  15. Java 遍历JsonNode
  16. matlab绘制频谱图代码,用MATLAB实现函数的频谱图
  17. 模拟器xposed框架安装7.1-64教程
  18. unity4和unity5区别
  19. 【简易教程】使用3dmax利用网上免费人物模型来制作人物动作动画
  20. 专题二 MATLAB矩阵处理

热门文章

  1. TF之CNN:利用sklearn(自带手写数字图片识别数据集)使用dropout解决学习中overfitting的问题+Tensorboard显示变化曲线
  2. C#实现水晶报表绑定数据并实现打印
  3. javascript与DOM的渊源
  4. [唐胡璐]Java操作Sql Server 2008数据库
  5. vaddin使用技巧
  6. Heartbeat,来点真的
  7. SUMO 设置车辆的换道模型
  8. SysTick的优先级是高还是低
  9. 中断处理函数中自旋锁的应用
  10. Bitcoin0.21版 公链开发(1) Bitcoind 、Bitcoin-qt编译