河南多校大一训练赛 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 ...
随机推荐
- python [1:3]
Python下标是以0开始的x[1:3]表示返回集合中下标1至3(不包括3)的元素集合x[:3] 表示返回从开始到下标3(不包括3)的元素集合x[3:]表示返回从下标3到结束的元素集合X[:]表示返回 ...
- 让人头疼的CSS兼容
先说点Hack的知识(真正的高手是不用Hack的,但要成为高手必须通过Hack这一关) /* CSS属性级Hack */ color:red; /* 所有浏览器可识别*/ _color:red; /* ...
- android 录制视频方式
http://www.cnblogs.com/skyseraph/archive/2012/03/31/2427593.html http://bbs.csdn.net/topics/39088448 ...
- 委托的BeginInvoke和EndInvoke方法
.NET Framework 允许异步调用任何方法,为了实现异步调用目标,需要定义与被调用方法具有相同签名的委托.公共语言运行时会自动使用适当的签名为该委托定义 BeginInvoke 和 EndIn ...
- Java Web开发: Tomcat中部署项目的三种方法
web开发,在tomcat中部署项目的方法: 可以参考http://m.blog.csdn.net/blog/u012516903/15741727 定义$CATALINA_HOME指的是Tomcat ...
- 用VS2012或VS2013在win7下编写的程序在XP下运行就出现“不是有效的win32应用程序
经常创建项目的时候,采用空项目,那么编译成功后,最好修改下sbusystem . 链接器->系统->子系统->控制台或windows 后面的"最低版本"是5.01
- OpenCV 图片尺寸调整
http://blog.csdn.net/xiaoshengforever/article/details/12191303 2013-09-30 12:21 10842人阅读 评论(0) 收藏 举报 ...
- 解决Xcode 9.2系统真机测试时出现 could not find developer disk image问题
解决Xcode在ipad/iphone 9.2 系统真机测试时出现could not find developer disk image问题 第一种方法:拷贝这个文件(http://download. ...
- centos精简系统 源码安装客户端git
CentOS的yum源中git版本比较低,需要最新版本git,只能自己编译安装,现在记录下编译安装的内容,留给自己备忘. 对于精简型的centos系统,会缺少很多依赖包和插件,要源码安装客户端git, ...
- url重写步骤
url重写:在global文件中,在application_BeginRequest事件中1:获取URL string url=Request.AppRelativeCurrentExecutionF ...