LightOJ - 1078-Integer Divisibility(同余)
链接:
https://vjudge.net/problem/LightOJ-1078
题意:
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.
思路:
\((a*x+y)%b = (a%b*x%b+y%b)%b\)
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
typedef long long LL;
const int INF = 1e9;
const int MAXN = 1e6+10;
const int MOD = 1e9+7;
int main()
{
int t, cnt = 0;
LL n, x;
scanf("%d", &t);
while(t--)
{
scanf("%lld%lld", &n, &x);
printf("Case %d: ", ++cnt);
if (x%n == 0)
puts("1");
else
{
int cnt = 1;
int tmp = x;
while(x!=0)
{
x = (x*10+tmp)%n;
cnt++;
}
printf("%d\n", cnt);
}
}
return 0;
}
LightOJ - 1078-Integer Divisibility(同余)的更多相关文章
- light oj 1078 - Integer Divisibility
1078 - Integer Divisibility PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...
- lightoj 1078【同余定理】
题意: 给你一个n和一个数 digit ,问你最少需要多少个 digit 使得整除于n; 思路: 同余定理(a+b)%n=(a%n+b%n)%n; (m%n+m%n*10+m%n*100+m%n*10 ...
- NEERC 1999 Divisibility /// 同余DP oj22640
题目大意: 输入n,m: ( 1 ≤ N ≤ 10000, 2 ≤ M ≤ 100 ) 接下来n个数:Each integer is not greater than 10000 by it's ab ...
- lightoj刷题日记
提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...
- 由一个多线程共享Integer类变量问题引起的。。。
最近看到一个多线程面试题,有三个线程分别打印A.B.C,请用多线程编程实现,在屏幕上循环打印10次ABCABC- 看到这个题目,首先想到的是解决方法是定义一个Integer类对象,初始化为0,由3个线 ...
- LeetCode 7 Reverse Integer & int
Reverse Integer 想用余10直接算,没想到 -123%10 是 7, 原因 -123-(-123//10*10) r=a-n*[a/n] 以上,r是余数,a是被除数,n是除数. 唯一不同 ...
- 豪迈开料锯MDB文件分析
豪迈CuteRite(简称CR)优化板件后会生成SAW文件.MDB文件,SAW文件用于开料机开料,MDB文件中保存了有限的优化结果记录. 因为CR软件可以根据配置生成不同结构的mdb文件,所以以下内容 ...
- 1214 - Large Division -- LightOj(大数取余)
http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一 ...
- SGU 140. Integer Sequences 线性同余,数论 难度:2
140. Integer Sequences time limit per test: 0.25 sec. memory limit per test: 4096 KB A sequence A is ...
随机推荐
- juc-locks包
1. 简介 java.util.concurrent.locks 包含常用的锁实现,重点研究AbstractQueuedSynchronizer.ReentrantLock.ReentrantRead ...
- golang使用一个二叉树来实现一个插入排序
思路不太好理解,请用断点 package main import "fmt" type tree struct { value int left, right *tree } fu ...
- 2019牛客暑期多校训练营(第四场)A meeting(dfs或dp,dp待更新)
示例1: 输入: 4 21 23 13 42 4 输出:2 说明: They can meet at place 1 or 3. 题意:从K个点到达不联通图某个点需要的最短时间,这个最短时间是这K个人 ...
- SAS学习笔记53 RTF单个字符标记设置
如何设置RTF中某一个字斜体而之后的字不斜体.下图中第一个P值都斜体并且加粗,第二个P值只有P进行了斜体和加粗
- websocket 协议简述
WebSocket 是一种网络通信协议,RFC 6455 定义了它的通信标准,属于服务器推送技术的一种 由于 HTTP 无状态.无连接.单向通信的特性,导致 HTTP 协议无法实现服务器主动向客户端发 ...
- Luogu5290 [十二省联考2019] 春节十二响 【贪心】【堆】
题目分析: 对于一个根,假设我们对每个子树分别求出了一种答案,那么怎么合并答案是最小的呢? 首先考虑这些答案里面最大的那个数字,它肯定要融合其它组里面的最大数字.以此类推 所以最好的合并方式是,每个子 ...
- C#在txt类文件中追加内容
string path = "test.txt"; FileStream mystream = new FileStream(path, FileMode.OpenOrCreate ...
- 关于Vue-ElementUI修改默认样式不成功问题解决
Element是一个很好用的组件库,但是有时候我们需要修改一些组件的样式以满足我们自己的需求. 我们用浏览器调试找到相应的class,在本地重写这个class时,发现修改不成功. 这是因为在Vue文件 ...
- 大专生自学web前端到找到工作的经验
先做个自我介绍,我13年考上一所很烂专科民办的学校,学的是生物专业,具体的学校名称我就不说出来献丑了.13年我就辍学了,我在那样的学校,一年学费要1万多,但是根本没有人学习,我实在看不到希望,我就退学 ...
- ABAP-信息结构S901/S902程序问题
1.问题 信息结构请求传入正式环境后,RMCX0070/RMCX0071程序执行DUMP,无法调用程序SAPFMCBF中的子FORM程序 MCB1_901 或是 MCB2_901 . 2.经查SAPF ...