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对 素数 取余 看看是否为 ...
随机推荐
- eclipse中删除tomcat server 导致不能重新创建该server
定位到:workspace\.metadata\.plugins\org.eclipse.core.runtime\.settings 1 打开org.eclipse.jst.server.tomca ...
- 用nfs挂载内核时出错 ERROR: Cannot umount的解决办法
SMDK2440 # nfs 30000000 192.168.1.106:/work/nfs_root/uImage ERROR: resetting ...
- JeeSite入门介绍(一)
JeeSite特点:高效.高性能.强安全性属于开源.JavaEE快速开发平台:接私活的最佳助手: JeeSite是在Spring Framework基础上搭建的一个Java基础开发平台,以Spring ...
- 记工作的变化--入住DB
2013年11月1日----一个值得纪念的日子! 今天才是我作为一个劳动者,步入社会的真正开始. 以前一直觉得做技术的技术做好就行了不用在意其余的细节.现实是做人(沟通)比做技术更重要! 以前一直觉得 ...
- 问题:System.Guid.NewGuid();结果:C# System.Guid.NewGuid()
C# System.Guid.NewGuid() 概念 GUID: 即Globally Unique Identifier(全球唯一标识符) 也称作 UUID(Universally Unique I ...
- jQuery选择器整理
最使用近工作中常用到jQuery,在过滤器的使用方面生疏,所以本文整理了些有关知识点,以便于自己查找方便,或为朋友们提供方便! 一.基本选择器 $("#test") 选取id为te ...
- opencv中文网站相关下载
http://wiki.opencv.org.cn/index.php/Download
- 万恶的mysql deadlocks
https://github.com/aneasystone/mysql-deadlocks/blob/master/11.md https://blog.csdn.net/dhfzhishi/art ...
- AudioManager 音量『转』
获取系统音量 通过程序获取android系统手机的铃声和音量.同样,设置铃声和音量的方法也很简单! 设置音量的方法也很简单,AudioManager提供了方法: publicvoidsetStream ...
- day70-oracle PLSQL_02光标
涨工资之前员工的工资. 如果PLSQL程序没有commit的话,命令行这边的客户端是无法读到的.这是oracle数据库的隔离级别. 为什么在PLSQL程序中commit之后还是不行呢? PLSQL程序 ...