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对 素数 取余 看看是否为 ...
随机推荐
- Mybatis多参数查询映射
一.单个参数: public List<XXBean> getXXBeanList(String xxCode); <select id="getXXXBeanList&q ...
- mysql应用基本操作语句(转)
二.库操作 1..创建数据库 命令:create database <数据库名> 例如:建立一个名为xhkdb的数据库 mysql> create database xhkdb; 2 ...
- 问题:C#控制台;结果:C#限制程序只能运行一個实例 (防多开)
C# Console类的具体用法 作者: 字体:[增加 减小] 类型:转载 时间:2013-03-08 这篇文章主要介绍C# Console类的具体用法,需要的朋友可以参考下 Console.Wr ...
- JS写一个简单的程序,输入两个整数,打印这两个数的和,差,积,余数
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Spring装配各种类型bean
一.单属性值的装配 //setter注入,提供无参构造器,提供setXX方法 <property name="" value=""></pro ...
- linux动态内核模块编程-3
将一组与模块相关的命令加载进内核 完成功能类似2,打印proc下的相关信息.但是不用重新编译内核,节省时间,更为灵活 内核模块介绍 模块是在内核空间运行的程序,实际上是一种目标文件,不能单独运行但其代 ...
- 深入理解js的变量提升和函数提升(转)
一.变量提升 在ES6之前,JavaScript没有块级作用域(一对花括号{}即为一个块级作用域),只有全局作用域和函数作用域.变量提升即将变量声明提升到它所在作用域的最开始的部分.上个简历的例子如: ...
- multi-mechanize安装实践
关于multi-mechanize的详细介绍参见如下链接,是其官网 http://testutils.org/multi-mechanize/setup.html multi-mechanize是一款 ...
- css选择器的一些说明
标签选择器.ID选择器.类选择器 这三个很简单,没啥可说的. 子选择器得说一下. <ul class="food"> <li>水果 &l ...
- android json解析(JSONObject方法实现)
今天刚刚学到json解析,看了一整天,大概了解到json就是你通过一个API(我用的聚合数据的API)发送一个请求,接着会收到json数据,比如说天气预报吧,他会给你发送一大段字符串,大概是未来几天的 ...