light oj 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的更多相关文章
- Light OJ 1078
题意: 给你 N,K 输出 KKKK.....KK能整除 N, 输出 K 的个数, (最小) 基础数学, 取摸运算即可. #include<bits/stdc++.h> using nam ...
- Light OJ 1114 Easily Readable 字典树
题目来源:Light OJ 1114 Easily Readable 题意:求一个句子有多少种组成方案 仅仅要满足每一个单词的首尾字符一样 中间顺序能够变化 思路:每一个单词除了首尾 中间的字符排序 ...
- Light OJ 1429 Assassin`s Creed (II) BFS+缩点+最小路径覆盖
题目来源:Light OJ 1429 Assassin`s Creed (II) 题意:最少几个人走全然图 能够反复走 有向图 思路:假设是DAG图而且每一个点不能反复走 那么就是裸的最小路径覆盖 如 ...
- Light OJ 1406 Assassin`s Creed 减少国家DP+支撑点甚至通缩+最小路径覆盖
标题来源:problem=1406">Light OJ 1406 Assassin`s Creed 意甲冠军:向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路: ...
- Light OJ 1316 A Wedding Party 最短路+状态压缩DP
题目来源:Light OJ 1316 1316 - A Wedding Party 题意:和HDU 4284 差点儿相同 有一些商店 从起点到终点在走过尽量多商店的情况下求最短路 思路:首先预处理每两 ...
- light oj 1007 Mathematically Hard (欧拉函数)
题目地址:light oj 1007 第一发欧拉函数. 欧拉函数重要性质: 设a为N的质因数.若(N % a == 0 && (N / a) % a == 0) 则有E(N)=E(N ...
- Light OJ 1406 Assassin`s Creed 状态压缩DP+强连通缩点+最小路径覆盖
题目来源:Light OJ 1406 Assassin`s Creed 题意:有向图 派出最少的人经过全部的城市 而且每一个人不能走别人走过的地方 思路:最少的的人能够走全然图 明显是最小路径覆盖问题 ...
- Light OJ 1288 Subsets Forming Perfect Squares 高斯消元求矩阵的秩
题目来源:Light OJ 1288 Subsets Forming Perfect Squares 题意:给你n个数 选出一些数 他们的乘积是全然平方数 求有多少种方案 思路:每一个数分解因子 每隔 ...
- Jan's light oj 01--二分搜索篇
碰到的一般题型:1.准确值二分查找,或者三分查找(类似二次函数的模型). 2.与计算几何相结合答案精度要求比较高的二分查找,有时与圆有关系时需要用到反三角函数利用 角度解题. 3.不好直接求解的一类计 ...
随机推荐
- [topcoder]FlowerGarden
1.此题很勉强算DP.找了半天网上思路,是个三层的循环,n^3.2.基本思路就是先找到在第一个位置的花.这样就双层遍历,找到所有和其他不冲突的花中最高的一个,然后放到结果的首位.然后去掉此花,继续使用 ...
- AD15高版软件卡不卡,问题解决大讨论
AD高版软件很卡(包括13 14 15版),这是我遇到过的问题,大家都遇到过的问题, 这里我分享一个解决办法:也请给位有什么好的方法也一起分享. 问题1卡:打开AD15软件, 按住鼠标中键 放大 或 ...
- Eclipse中查看Android模拟器SD卡目录
· 有时候用到Android模拟器来模拟SD卡相关操作,在Eclipse中可以直接查看SD卡目录: 首先,新建模拟器的时候要创建SD卡,存储的大小根据需要创建: 启动模拟器,在Eclipse中打开视图 ...
- IntelliJ IDEA MyBatis插件安装
打开IntelliJ IDEA工具,打开菜单File--> Settings 选择 Plugins,点击Browse repositories,在搜索框输入MyBatis.
- Java读写Windows共享文件夹 .
版权声明:本文为博主原创文章,未经博主允许不得转载. 项目常常需要有访问共享文件夹的需求,例如共享文件夹存储照片.文件等.那么如何使用Java读写Windows共享文件夹呢? Java可以使用JCIF ...
- python学习笔记一--字符串
一.字符串: (一)字符串里单个元素的操作 1. 单个字符(元素)的序列组合. 2. 序列:单个字符的位置 3. 序列的操作:内置函数len获取长度,加位置索引 4. 获取字符串的里的元素:正向索引+ ...
- left (outer) join , right (outer) join, full (outer) join, (inner) join, cross join 区别
z -- -- select a.*,b.* from a left join b on a.k = b.k select a ...
- SQL Server中Delete语句表名不能用别名
delete from TABLEA A where A.FIELD1=10 (ORACLE适用)delete TABLEA from TABLEA A where A.FIELD1=1 ...
- MYI 文件内容
参考 http://blog.itpub.net/703656/viewspace-1018470/ 创建表结构 create table test(name char(20), age int, c ...
- [转]Linux下Nagios的安装与配置
转自:http://blog.chinaunix.net/uid-29539073-id-4149856.html 月色书香 一.Nagios简介 Nagios是一款开源的电脑系统和网络监视工具,能有 ...