链接:

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(同余)的更多相关文章

  1. light oj 1078 - Integer Divisibility

    1078 - Integer Divisibility   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 3 ...

  2. 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 ...

  3. 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 ...

  4. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  5. 由一个多线程共享Integer类变量问题引起的。。。

    最近看到一个多线程面试题,有三个线程分别打印A.B.C,请用多线程编程实现,在屏幕上循环打印10次ABCABC- 看到这个题目,首先想到的是解决方法是定义一个Integer类对象,初始化为0,由3个线 ...

  6. LeetCode 7 Reverse Integer & int

    Reverse Integer 想用余10直接算,没想到 -123%10 是 7, 原因 -123-(-123//10*10) r=a-n*[a/n] 以上,r是余数,a是被除数,n是除数. 唯一不同 ...

  7. 豪迈开料锯MDB文件分析

    豪迈CuteRite(简称CR)优化板件后会生成SAW文件.MDB文件,SAW文件用于开料机开料,MDB文件中保存了有限的优化结果记录. 因为CR软件可以根据配置生成不同结构的mdb文件,所以以下内容 ...

  8. 1214 - Large Division -- LightOj(大数取余)

    http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一 ...

  9. 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 ...

随机推荐

  1. PC电脑看电视 / 电视直播 / 高清频道 / 直播源

    打开方式 PotPlayer + .m3u播放列表 效果图 .m3u播放列表 #EXTM3U #EXTINF:150,CCTV1综合 http://183.251.61.207/PLTV/888888 ...

  2. C之volatile

    https://blog.csdn.net/vay0721/article/details/79035854 https://blog.csdn.net/kaychangeek/article/det ...

  3. 机器学习xgboost参数解释笔记

    首先xgboost有两种接口,xgboost自带API和Scikit-Learn的API,具体用法有细微的差别但不大. 在运行 XGBoost 之前, 我们必须设置三种类型的参数: (常规参数)gen ...

  4. Linux文件和目录相关的命令

    当前目录 .     上一层目录 ..     tab键 自动补全             查看目录内容 ls 以.开头的都是隐藏文件需要用-a才能显示出来 ls通配符的使用 * 代表任意个数个字符 ...

  5. Scratch编程:游来游去的鱼(二)

    “ Scratch编程学习环境搭建好了吗?让我们一起来进行游戏吧!” 01 — 游戏介绍 这是一款简单的小游戏,实现了一条小鱼在池塘里游来游去. 02 — 设计思路 1,这个游戏主要由一个池塘背景和一 ...

  6. 编译 Linux 内核 时出现 Restart config 问题

    scripts/kconfig/conf --silentoldconfig Kconfig * * Restart config... * * * Enable the block layer * ...

  7. C++ 异步编程:Boost.Asio

    Boost.Asio 是一个用于网络和低级 I/O 编程的跨平台 C++ 库,它使用现代 C++ 方法为开发人员提供一致的异步模型 一个异步使用计时器的样例 #include <iostream ...

  8. Spring Cloud Alibaba学习笔记(5) - 整合Sentinel及Sentinel规则

    整合Sentinel 应用整合Sentinel 在dependencies中添加依赖,即可整合Sentinel <dependency> <groupId>com.alibab ...

  9. 优先队列问题 get it !!

    首先 队列的基本用法 头文件 #include<queue> priority_queue < int/string/struct> q//  q为队列的名字 基本操作 q.p ...

  10. 针对Web的攻击技术

    主动攻击 SQL注入攻击 OS命令注入攻击 会话劫持 被动攻击 XSS攻击 CSRF攻击 HTTP首部注入攻击 会话固定攻击 一.主动攻击 1.SQL注入攻击(案例) 什么是SQL? SQL是用来操作 ...