LightOj 1078 Basic Math
思路:
设输入的两个数分别为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 Yuantime : 2014/8/21 0:28algorithm: Basic Mathsource : LightOj 1078
**********************************/
#include<bits/stdc++.h>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
LightOj 1078 Basic Math相关推荐
- LightOJ 1078 Integer Divisibility (同余定理)
题目: If an integer is not divisible by 2 or 5, some multiple of that number in decimal notation is a ...
- English Spoken Math
1. Basic math symbols Symbol Symbol Name Example = equals 5 = 2+3 5 is equal to 2+3 ≠ not equal to 5 ...
- tensorflow编程: Math
Arithmetic Operators tf.add.tf.subtract.tf.multiply.tf.scalar_mul.tf.div.tf.divide.tf.truediv.tf.flo ...
- C++向量类模板(支持实数向量与复数向量的各种运算)
2019独角兽企业重金招聘Python工程师标准>>> 头文件: /** Copyright (c) 2008-2011 Zhang Ming (M. Zhang), zmjerry ...
- 【ACM】杭电OJ 4704 Sum (隔板原理+组合数求和公式+费马小定理+快速幂)
http://acm.hdu.edu.cn/showproblem.php?pid=4704 1.隔板原理 1~N有N个元素,每个元素代表一个1.分成K个数,即在(N-1)个空挡里放置(K-1)块隔板 ...
- BNUOJ34980方(芳)格(哥)取数(好坑)
方(芳)格(哥)取数 Time Limit: 3000ms Memory Limit: 65536KB 64-bit integer IO format: %lld Java class n ...
- 读书笔记2013第10本:《学得少却考得好Learn More Study Less》
<学得少却考得好Learn More Study Less>这本书最早是从褪墨网站上看到的,crowncheng翻译了全文.这本书介绍了不少学习方法,非常适合在校的学生,原文的作者Scot ...
- 测试框架 Jest 实例教程
Jest 是由 Facebook 开源出来的一个测试框架,它集成了断言库.mock.快照测试.覆盖率报告等功能.它非常适合用来测试 React 代码,但不仅仅如此,所有的 js 代码都可以使用 Jes ...
- tensorflow随笔-求平均值的函数
求平均值的函数 reduce_mean axis为1表示求行 axis为0表示求列 >>> xxx=tf.constant([[1., 10.],[3.,30.]]) >> ...
最新文章
- MVC/MVP/MVVM区别——MVVM就是angular,视图和数据双向绑定
- discuzx2.5添加自定义积分日志
- Netflix 如何使用机器学习来提升流媒体质量
- 串口光猫设备结构及主要特点介绍
- Md5 Md5实现原理
- 7-69 超市促销 (6 分)
- linux批量安装 五大开源软件挨个看,Linux批量安装 五大开源软件挨个看(1)(5)
- Pyke 逻辑编程入门(16):知识库之“问题库”
- 【机器视觉】机器人及视觉检测系统在螺丝检测包装生产线上的应用
- ADSL共享方法总结(转)
- html怎么去除em的倾斜,HTML5 :b/strong加粗,i/em倾斜区别
- 记一次rk平台热点打开流程追踪记录
- 原创安卓手机QQ7.0登录界面动态背景视频实现方案
- VFS中的read/write系统调用
- 用python3+	PyQt5写一个NFC模块的串口小工具的一星期
- Linux内核固定虚拟地址映射
- html做成绩查询,一个简单的成绩查询系统
- 一个JAVA渣渣的校招成长记,附BAT美团网易等20家面经总结
- 目标检测(3)—— 如何使用PyTorch加载COCO类型的数据集
- 攻防演练-一次内网渗透