博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
LightOj 1078 Basic Math
阅读量:4309 次
发布时间:2019-06-06

本文共 1891 字,大约阅读时间需要 6 分钟。

思路:

    设输入的两个数分别为n和a,每一次所得到的数为update:

    开始update=a,依次update分别为update*10+a,这样数据会超出范围,则update每次为update=(update*10+a)%n即可,

    如果update=0,跳出循环;

    只需证明:(update*10+a)%n=(update%n*10+a)%n即可;

                      由(update*10+a)%n=(update%n*10+a%n)%n,因为a<=n,所以a%n=a.证必;

1078 - Integer Divisibility

PDF (English) Statistics Forum
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
PROBLEM SETTER: JANE ALAM JAN

/********************************    author   : Grant Yuan    time     : 2014/8/21 0:28    algorithm: Basic Math    source   : LightOj 1078**********************************/#include
using namespace std;int t;int a,b,ans;int main(){ scanf("%d",&t); for(int i=1;i<=t;i++) { ans=1; scanf("%d%d",&a,&b); int temp=b; while(temp%a!=0) { temp=temp*10; temp+=b; temp%=a; ans++; } printf("Case %d: %d\n",i,ans); } return 0;}

 

转载于:https://www.cnblogs.com/codeyuan/p/4254449.html

你可能感兴趣的文章
海量数据处理 - 10亿个数中找出最大的10000个数(top K问题)(转)
查看>>
word交叉引用公式编号时和连公式一起引用
查看>>
P1163 第K极值 - Smart Online Judge
查看>>
Unity3D 新版本场景转换
查看>>
Android--获取App应用程序的大小
查看>>
Java Timer触发定时器
查看>>
Page Object设计模式
查看>>
程序的基础知识
查看>>
linux中的软连接和硬连接
查看>>
DFS专题 Prime Ring Problem
查看>>
jQuery源码解析 事件
查看>>
数字格式化NumberFormat
查看>>
ajax例子
查看>>
漫画阅读器ComicReader应用源码
查看>>
html中引入调用另一个html文件
查看>>
旧代码中的"enum hack"
查看>>
如何禁止某个linux用户访问某些文件夹及执行某些命令
查看>>
javascript学习之: 前端模块化
查看>>
A. Ice Skating (联通块)
查看>>
拦截器与过滤器的不同点
查看>>