河南多校大一训练赛 D
题目链接:http://acm.hust.edu.cn/vjudge/contest/125004#problem/D
密码:acm
Description
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 Sample Output
Case :
Case :
Case :
分析:
第一次代码,超了应该,反正看输不出结果:
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; int main()
{
int n,i,o=,a,b;
scanf("%d", &n); for(i=;i<=n;i++)
{
scanf("%d%d", &a,&b);
int d=b,ans=; while(d%a)
{
d=d*+b;
ans++;
} printf("Case %d: %d\n", o++,ans);
}
return ;
}
修改后:
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std; int main()
{
int n,i,o=,a,b;
scanf("%d", &n); for(i=;i<=n;i++)
{
scanf("%d%d", &a,&b);
int d=b,ans=,r; r=b%a;
while(r)
{
d=r*+b;
ans++;
r=d%a;
} printf("Case %d: %d\n", o++,ans);
}
return ;
}
河南多校大一训练赛 D的更多相关文章
- 河南多校大一训练赛 G 硬币
题目链接:http://acm.hust.edu.cn/vjudge/contest/125004#problem/G 密码:acm Description 宇航员Bob有一天来到火星上,他有收集硬币 ...
- 河南多校大一训练赛 C 青蛙的约会
题目链接:http://acm.hust.edu.cn/vjudge/contest/125004#problem/C 密码:acm Description 两只青蛙在网上相识了,它们聊得很开心,于是 ...
- 河南多校大一训练赛 E 开餐馆
题目链接:http://acm.hust.edu.cn/vjudge/contest/125004#problem/E 密码:acm Description 北大信息学院的同学小明毕业之后打算创业开餐 ...
- 2014 多校联合训练赛6 Fighting the Landlords
本场比赛的三个水题之一,题意是两个玩家每人都持有一手牌,问第一个玩家是否有一种出牌方法使得在第一回和对方无牌可出.直接模拟即可,注意一次出完的情况,一开始没主意,wa了一发. #include< ...
- 河南多校联合训练 南阳理工 1261 音痴又音痴的LT
描述 LT最近一直在无限循环薛之谦的歌,简直都中毒了!可是呢…他的歌LT还是不会唱(其实不止他的歌LT不会唱,所有人的歌LT都不会唱…因为LT是标准的音痴)可是LT又很喜欢唱歌(所以LT不仅是音痴还是 ...
- 河南多校联合训练 F 不是匹配
描述 有N个人,N个活动, 每个人只会对2个或者3个活动感兴趣, 每个活动也只有两个人或者两个活动对它兴趣,每个人参加一个 感兴趣的活动需要一天 ,且当天该活动被参加时,其他的人不能参加 如果 ...
- hdu 5381 The sum of gcd 2015多校联合训练赛#8莫队算法
The sum of gcd Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) T ...
- 2015多校联合训练赛 Training Contest 4 1008
构造题: 比赛的时候只想到:前面一样的数,后面 是类似1,2,3,4,5,6....t这 既是:t+1,t+1...,1,2,3,...t t+1的数目 可能 很多, 题解时YY出一个N 然后对N ...
- hdu 5358 First One 2015多校联合训练赛#6 枚举
First One Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Tota ...
随机推荐
- 2016-02-03 JS正则表达式
var reg = new RegExp("^(([1-9]{1,2})|100)$"); var strRate = $('#GOODS_SPEC_DEPOSIT_RATE'). ...
- Chapter 14_5 _ENV和load
load在加载代码块时,通常使用全局环境去初始化代码块的_ENV上值. 然而,load选项的第四个参数给出的值就是供_ENV用的.(loadfile函数参数也是一样) 举一个有关初始化的例子,假如我们 ...
- Python 学习笔记3
人如果从来没有怀疑过自己,那他永远都不会进步. 今天学习Python解释器及其环境. http://www.pythondoc.com/pythontutorial3/interpreter.html
- SQL多表连接查询以及mysql数据库、sqlserver数据库常见不同点
mysql数据库表及数据准备语句: USE test; DROP TABLE IF EXISTS `teacher_table`; DROP TABLE IF EXISTS `student_tabl ...
- AutoTile 自动拼接 番外篇(自动融合技术)
http://pan.baidu.com/s/1dDQyfSl 密码:ttud 先睹为快吧. 之后 还差一个 智能替换 技术.
- android 常用
1:常用之动画(View Animation,Drawable Animation,Property Animation) http://blog.csdn.net/huxueyan521/artic ...
- git容易被忽略的准备工作命令
安装git命令 $ apt-get install git-core 配置用户信息 $ git config --global user.name "wxw" $ git conf ...
- python2.7学习记录之二
一.高级特性 1.切片取前3个元素用L[0:3]表示,从索引0开始取,直到索引3为止,但不包括索引3.如果第一个索引是0可省略.前10个数 每两个取一个L[:10:2],所有数 每5个取一个L[::5 ...
- c语言-扑克牌小魔术
/************************************* Copyright(C) 2004-2005 vision,math,NJU. File Name: guess_card ...
- Chapter 2 Open Book——15
The rest of the week was uneventful. I got used to the routine of my classes. 这周剩下的时间都是平淡无事的.我就是正常的上 ...