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 ...
随机推荐
- 034 Android NavigationView和DrawerLayout实现抽屉式导航设计(侧边栏效果)
1.创建带侧滑效果的activity 右击,new---->activity---->选择NavgationDrawer Activity 2.xml文件布局 (1)activity_ma ...
- composer 无法配置命令行写入配置文件问题
composer config repo.packagist composer https://packagist.phpcomposer.com 这条命令无法修改composer.json 添加中国 ...
- Mkdown常用语法
这篇笔记停了两天,今天开始整理, 写这篇笔记主要是加强下自己的mkdown语法知识, 也当作练手之作. Mkdown 语法简介 标题 [h1 - h6] # ~ ###### 一般# 作为标题, 只有 ...
- struts下载文件错误,想不明白为什么更改变量名就不报错了
java.lang.IllegalArgumentException: Can not find a java.io.InputStream with the name [is] in the inv ...
- 剑指offer59:按之字形顺序打印二叉树:[[1], [3,2], [4,5,6,7]]
1 题目描述 请实现一个函数按照之字形打印二叉树,即第一行按照从左到右的顺序打印,第二层按照从右至左的顺序打印,第三行按照从左到右的顺序打印,其他行以此类推. 2 思路和方法 先给定一个二叉树的样式: ...
- BC26模组UDP调试
BC26模组调试 数据上报AT流程 [15:33:46.819]收←◆ F1: 0000 0000 V0: 0000 0000 [0001] 00: 0006 000C 01: 0000 0000 U ...
- 解决windows 激活问题
解决windows 激活问题 下载 然后 搞定 重启
- Challenge & Growth —— 从这里开始
做有挑战的事情,就从这里开始. 忘记这本书现在在哪儿了,以前还以为能祖祖辈辈留传,现在只能借助 Nowcoder 了.Now coder,Forever thinker. 想以自以为最优美的 code ...
- Luogu5290 [十二省联考2019] 春节十二响 【贪心】【堆】
题目分析: 对于一个根,假设我们对每个子树分别求出了一种答案,那么怎么合并答案是最小的呢? 首先考虑这些答案里面最大的那个数字,它肯定要融合其它组里面的最大数字.以此类推 所以最好的合并方式是,每个子 ...
- Java8新特性 - 新时间和日期 API
本地时间和时间戳 主要方法: now:静态方法,根据当前时间创建对象 of:静态方法,根据指定日期/时间创建对象 plusDays,plusWeeks,plusMonths,plusYears:向当前 ...