河南多校大一训练赛 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 ...
随机推荐
- 如何利用 MembershipUser 更改密码
如何利用 MembershipUser 更改密码 作者: vkvi 来源:千一网络 (原创) 时间: 2009-3-11 完美集成.增强 KindEditor HTML 编辑器 在 ASP.NET ...
- varnish屏蔽control+F5导致缓存失效
刚刚接触Varnish缓存,对静态资源进行缓存.目前问题,当浏览器Control+F5刷新页面,导致缓存失效. 参照:http://zhangxugg-163-com.iteye.com/blog/1 ...
- js iframe跨域访问
1.什么是跨域? 2.前台解决跨域几种方法 2.1 动态创建script 2.2 使用document.domain 2.3使用HTML5新属性postMessage 2.4 利用iframe和loc ...
- perl中的pack与unpack
这个pack, unpack在 "perl语言编程" 有介绍 看起来很复杂 #把一个字符串转为十六进制格式 my $source = 'abcd'; unpack('H*', $s ...
- HDU 4585 Shaolin (set的应用)
set是STL中非常方便的工具,可以实现自动去重和排序,可我一直忽视它的重要性,导致吃了好几次亏. 在思考这道题的时候,我一直往二分上靠拢,可是二分需要直接插入排序,直接插入排序覆盖的时候复杂度最大是 ...
- 笔记整理--Linux守护进程
Linux多进程开发(三)进程创建之守护进程的学习 - _Liang_Happy_Life__Dream - 51CTO技术博客 - Google Chrome (2013/10/11 16:48:2 ...
- VBS基础篇 - 对象(5) - File对象
VBS基础篇 - 对象(5) - File对象 描述:提供对文件所有属性的访问,从FSO对象的GetFile方法获得. 使用File对象 要用File对象模型来编程必须先用FileS ...
- Chapter 2 Open Book——5
I was relieved that I had the desk to myself, that Edward was absent. 我能一个人一张桌子很开心,就因为Edward 没来. I t ...
- thinkphp 实现微信公众号开发(二)--实现自定义菜单
IndexController.class.php <?php namespace Home\Controller; use Think\Controller; class IndexContr ...
- 删除 mysql 日志文件后 ,启动出错
把 mysql-bin.index 里面的索引全部删除