LightOJ - 1078-Integer Divisibility(同余)
2024-08-27 02:24:05
链接:
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;
}
最新文章
- Android中常见功能包描述(转)
- AOP动态代理解析5-cglib代理的实现
- uboot在s3c2440上的移植(1)
- Nginx+uWSGI+Django原理
- linux 进入包含空格文件名的文件夹
- MVVM架构~knockoutjs系列之表单添加(验证)与列表操作源码开放
- php ajax提交数据 在本地可以执行,而在服务器不能执行
- C#Windows Form简易计算器实现(中)
- Spring阅读方法
- Eclipse中tomcat配置
- Java限流策略
- ArcGIS JS 3.x使用webgl绘制热力图
- java----字符串的大写字母右移
- linux centos7添加ip黑名单禁止某个ip访问
- 安装 jenkins
- Mongodb内嵌数组的完全匹配查询
- CentOS 几种重启方式的区别
- Opengl绘制我们的小屋(二)第一人称漫游
- paramiko 简单的使用
- Grid Search学习