L - Large Division (大数, 同余)
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an integer a is divisible by an integer b if and only if there exists an integer c such that a = b * c.
Input
Input starts with an integer T (≤ 525), denoting the number of test cases.
Each case starts with a line containing two integers a (-10200 ≤ a ≤ 10200) and b (|b| > 0, b fits into a 32 bit signed integer). Numbers will not contain leading zeroes.
Output
For each case, print the case number first. Then print 'divisible' if a is divisible by b. Otherwise print 'not divisible'.
Sample Input
6
101 101
0 67
-101 101
7678123668327637674887634 101
11010000000000000000 256
-202202202202000202202202 -101
Sample Output
Case 1: divisible
Case 2: divisible
Case 3: divisible
Case 4: not divisible
Case 5: divisible
Case 6: divisible
题解:用一个数组来存储大数,运用同余定理
(a*b)%c=(a%c*b%c)%c;
判断最后的余数是不是为零。注意:要用到long long型
AC代码
#include<stdio.h>
#include<string.h> int main()
{
int n;
char a[];
int b, num = ;
long long sum;
scanf("%d", &n);
while(n--)
{
sum = ;
scanf("%s %d", a, &b);
int len = strlen(a);
for(int i = ; i < len; i++)
{
if(a[i] != '-')
{
sum = (sum* + a[i] - '') % b;
}
}
num++;
if(sum == )
printf("Case %d: divisible\n", num);
else
printf("Case %d: not divisible\n", num);
} return ;
}
L - Large Division (大数, 同余)的更多相关文章
- Large Division (大数求余)
Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...
- LightOJ1214 Large Division —— 大数求模
题目链接:https://vjudge.net/problem/LightOJ-1214 1214 - Large Division PDF (English) Statistics Forum ...
- light oj 1214 - Large Division 大数除法
1214 - Large Division Given two integers, a and b, you should check whether a is divisible by b or n ...
- 1214 - Large Division -- LightOj(大数取余)
http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一 ...
- (大数 求余) Large Division Light OJ 1214
Large Division Given two integers, a and b, you should check whether a is divisible by b or not. We ...
- K - Large Division 判断a是否是b的倍数。 a (-10^200 ≤ a ≤ 10^200) and b (|b| > 0, b fits into a 32 bit signed integer). 思路:取余;
/** 题目:K - Large Division 链接:https://vjudge.net/contest/154246#problem/K 题意:判断a是否是b的倍数. a (-10^200 ≤ ...
- lightoj--1214--Large Division(大数取余)
Large Division Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %lld & %llu Submit ...
- LightOJ 1214 Large Division
Large Division Given two integers, a and b, you should check whether a is divisible by b or not. We ...
- POJ2635The Embarrassed Cryptographer(大数取余+素数筛选+好题)
题目链接 题意:K是由两个素数乘积,如果最小的素数小于L,输出BAD最小的素数,否则输出GOOD 分析 素数打表将 L 大点的素数打出来,一定要比L大,然后就开始枚举,只需K对 素数 取余 看看是否为 ...
随机推荐
- Mingw版QtCreator调用VS编译的C++库的方法
https://wenku.baidu.com/view/ae3667fe0b1c59eef8c7b4bc.html
- VS编译linux项目生成静态库并在另一个项目中静态链接的方法
VS2017也推出很久了,在单位的时候写linux的服务端程序只能用vim,这让用惯了IDE的我很难受. 加上想自己撸一套linux上的轮子,决定用VS开工远程编写调试linux程序. 在window ...
- 【转】LTE 全过程流程
LTE 过程全流程 1. UE处于关闭状态 2. 打开UE电源. 3. 搜索附近的频率 4. 同步时间 5. 小区搜索 6. 小区选择 7. 解码MIB 8. 解码SIB 9. 初始化RACH过程 1 ...
- 第十章 Executor框架
在Java中,使用线程来异步执行任务.Java线程的创建与销毁需要一定的开销,如果我们为每一个任务创建一个新线程来执行,这些线程的创建与销毁将消耗大量的计算资源.同时,为每一个任务创建一个新线程来执行 ...
- rsync 同步mac机器目录数据到windows2008R2
openssh rsync -azvP --progress -e "ssh -p 6099" /ahwater/rsync/ ahwater@ip:/ahwater
- SpringMVC的Date与String互转
摘要: 项目里经常需要用到日期和String之间的转换,比如后台的Date对象以Json形式返回给前端页面的时候,希望转换为yyyy-MM-dd HH:mm:ss格式的字符串,而前端页面 ...
- java常用八大排序法
最近查资料发现java排序挺有意思的,其中包含常见八种具有代表性的排序法:笔者觉得排序的功能重要,但更重要的是排序的思想:所以简单叙述一下常见排序方法名称,并用代码举例. A.插入排序(直接插入排序. ...
- xcode减小静态库的大小(转)
减小静态库的大小 编译生成的.a文件太大,但又没有冗余的文件可以删除已减少体积,找了很久才找到解决办法,如下: Build Settings-->Generate Debug Symbols 将 ...
- DAY15-Django模板语言
Django模板系统 官方文档 你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python代码之中. def current_datetime(reque ...
- python之简单的函数介绍(http://docs.python.org/3/library)
Python不但能非常灵活地定义函数,而且本身内置了很多有用的函数,可以直接调用. 在上面的网站上我们可以进行查询,Python具体都有哪些函数. 我们也可以再交互命令行中来查找函数: >> ...