1078 - Integer Divisibility
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

题意:给出 n和m,让判断多少位的m可以整除n(每一位的数值都为m,如果当前的位数不能整除n则再加上一位)如:3   1意思是多少个1可以整除3显然111可以整除3,所以就是三位,输出3

小技巧:令ans=m 让ans对n取余为ans(覆盖原来的值),每次让ans=ans*10+m(因为不能整除所以增加位数)直到可以整除   原理大概是除法的同余定理吧

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<math.h>
#define LL long long
#define DD double
#define MAX 10000
using namespace std;
int main()
{
int t;
int n,m,j,i;
LL ans;
scanf("%d",&t);
int k=1;
while(t--)
{
scanf("%d%d",&n,&m);
printf("Case %d: ",k++);
ans=m;
int sum=1;
while(ans%n)
{
ans=ans%n;
ans=ans*10+m;
sum++;
}
printf("%d\n",sum);
}
return 0;
}

  

  

light oj 1078 - Integer Divisibility的更多相关文章

  1. Light OJ 1078

    题意: 给你 N,K 输出 KKKK.....KK能整除 N, 输出 K 的个数, (最小) 基础数学, 取摸运算即可. #include<bits/stdc++.h> using nam ...

  2. Light OJ 1114 Easily Readable 字典树

    题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...

  3. Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖

    题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...

  4. Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖

    标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...

  5. Light OJ 1316 A Wedding Party 最短路+状态压缩DP

    题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...

  6. light oj 1007 Mathematically Hard (欧拉函数)

    题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...

  7. Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖

    题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...

  8. Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩

    题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...

  9. Jan's light oj 01--二分搜索篇

    碰到的一般题型:1.准确值二分查找,或者三分查找(类似二次函数的模型). 2.与计算几何相结合答案精度要求比较高的二分查找,有时与圆有关系时需要用到反三角函数利用 角度解题. 3.不好直接求解的一类计 ...

随机推荐

  1. jmeter HTTP信息头管理器使用一例

    最近在测试过程中遇到一个问题,被测系统会检测http header:如果不包含制定内容会引发302跳转操作,从而是测试达不到效果.解决办法,增加http 信息头管理器,直接上图 此处注意: 1.此处“ ...

  2. [Gauss]HDOJ3364 Lanterns

    题意:有n个灯笼,m个开关 每个开关可以控制k个灯笼, 然后分别列出控制的灯笼的编号(灯笼编号为1到n) 下面有Q个询问,每个询问会有一个最终状态(n个灯笼为一个状态)0代表关 1代表开 问到达这种状 ...

  3. 几种必知的oracle结构图

    一.数据库结构 二.Oracle 内存结构 三.进程结构 1. 用户进程:在数据库用户请求连接到Oracle 服务器时启动 2. 服务器进程:可以连接到Oracle实例,它在用户建立会话时启动 3. ...

  4. 利用VC/VS的安装目录找到C/C++库函数实现的源代码

    2013-07-03 20:08:57 大多开发软件的装目录下都有很多有价值的东西,比如help文档.user guide.src文件等.今天在VS的安装目录下发现了库函数的源文件,这些文件中有对所有 ...

  5. git rev-list

    git-rev-list - Lists commit objects in reverse chronological order 按照时间顺序倒序排列的commit Update: If all ...

  6. Android开发之ADT导入Support Library

    在工程中增加(例如 support-v4 Library) 在ADT中需要按照以下步骤:  1.右击当前工程,查找Properties 2.选择Java Build Path 3.选择Librarie ...

  7. Android开发之布局的学习

    FrameLayout-帧布局 实现效果: 代码: <?xml version="1.0" encoding="utf-8"?> <Frame ...

  8. Codeforces Round #221 (Div. 2) Lever I.O.U.

    这场cf 做的很差,,第一题犯了一个很低级的错误..把i写成了J.... 第二题 想的太复杂了...其实我们只需要 考虑每个人自己的负债情况就行了,就是假设每个人把别人 欠他的钱,拿过来还给别人..这 ...

  9. POI使用cell.getCellStyle()设置指定单元格颜色,但是其它没有指定的单元格也会变色

    HSSFCell cell = row.createCell((short)i); cell.getCellStyle().setAlignment(HSSFCellStyle.ALIGN_RIGHT ...

  10. 使用Unity3d的Physics.Raycast()的用法做子弹射击

    Class Functions 1)static function Raycast (origin : Vector3, direction : Vector3, distance : float = ...