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

题意:给出t组数据,判断前者是否能被后者整除,能的话输出divisible,否则输出not divisible

思路:前者数据太大,用字符串输入,后者直接int输入即可。然后将前者每一位转换成int型,在每一位转换的时候进行取余。

  但是需要注意判断两者的正负,前者若为负直接将后面每一位往前移一位,且字符串长度记得-1;后者直接变符号即可。

取余操作:

for(int i=0; i<L; i++)
{
k=(k*10+a[i]-'0')%b;
}

上述还可以写成k=(k*10%b+a[i]-'0')%b;

同余定理:
      (a+b)%c=(a%c+b%c)%c
      (a*b)%c=(a%c*b%c)%c

大数取余操作:
一个大数对一个数取余,可以把大数看成各位数的权值与个
位数乘积的和。
1234 = ((1 * 10 + 2) * 10 + 3) * 10 + 4

 1 #include<stdio.h>
2 #include<cmath>
3 #include<string.h>
4 typedef long long ll;
5 using namespace std;
6
7 //const int N=2e200;
8 char a[20000];
9 int b;
10
11 int main()
12 {
13 int n;
14 int t;
15 scanf("%d",&t);
16 int tt=1;
17 while(t--)
18 {
19 scanf("%s %d",a,&b);
20 int L=strlen(a);
21 if(a[0]=='-')//判断前者字符串是否为负
22 {
23 for(int i=1; i<L; i++)
24 {
25 a[i-1]=a[i];
26 }
27 // strlen(a)--;
28 L--;//这里注意一下
29 }
30 if(b<0)//判断后者int是否为负
31 b=-b;
32
33 ll k=0;//这里要写成ll,不然WA
34 for(int i=0; i<L; i++)
35 {
36 k=(k*10+a[i]-'0')%b;
37 }
38 if(k==0)
39 printf("Case %d: divisible\n",tt++);
40 else
41 printf("Case %d: not divisible\n",tt++);
42 }
43 return 0;
44 }

LightOJ-1214-Large Division-大数取余的更多相关文章

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

  2. LightOJ 1214 Large Division

    Large Division Given two integers, a and b, you should check whether a is divisible by b or not. We ...

  3. LightOJ 1214 Large Division 水题

    java有大数模板 import java.util.Scanner; import java.math.*; public class Main { public static void main( ...

  4. Large Division (大数求余)

    Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...

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

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

  6. light oj 1214 - Large Division

    1214 - Large Division   PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB G ...

  7. LightOJ1214 Large Division —— 大数求模

    题目链接:https://vjudge.net/problem/LightOJ-1214 1214 - Large Division    PDF (English) Statistics Forum ...

  8. POJ2635The Embarrassed Cryptographer(大数取余+素数筛选+好题)

    题目链接 题意:K是由两个素数乘积,如果最小的素数小于L,输出BAD最小的素数,否则输出GOOD 分析 素数打表将 L 大点的素数打出来,一定要比L大,然后就开始枚举,只需K对 素数 取余 看看是否为 ...

  9. java大数取余

    java大数取余: 类方法:BigInteger.divideAndRemainder() 返回一个数组,key = 0为商key = 1为余数 import java.util.*; import ...

  10. hdu 1226 bfs+余数判重+大数取余

    题目: 超级密码 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

随机推荐

  1. leetcood学习笔记-204-计算质数

    题目描述: 第一次提交;(超时): class Solution: def countPrimes(self, n: int) -> int: count = 0 for i in range( ...

  2. Batch - forfiles 命令详解

    forfiles 命令详解 C:\Users\cuixunxu>forfiles /? FORFILES [/P pathname] [/M searchmask] [/S] [/C comma ...

  3. TStringGrid 实现下拉框

    TStringGrid 实现下拉框比较常见的思路是在TSringGrid中嵌入一个TComboBox ,思路虽然简单,但开发起来却很麻烦,而且有时会出现不愿看到的效果.还有一种更巧的方法,是Delph ...

  4. 暑假集训test-8-28

    大概是从我一年以来做过的最傻逼的一套题了.. 一个半小时打完三个程序三个暴力拍完以为自己AK了,开心地耍了两个小时. 结果T3要写高精,LL炸了后4个点,中间还有个点是啥都不选的,我没用0去更新又炸了 ...

  5. NX二次开发-获取坐标系信息UF_CSYS_ask_csys_info

    NX9+VS2012 #include <uf.h> #include <uf_csys.h> UF_initialize(); //获取WCS标识 tag_t WcsId = ...

  6. NX二次开发-输入X向量Y向量输出一个3*3矩阵UF_MTX3_initialize

    NX9+VS2012 #include <uf.h> #include <uf_csys.h> #include <uf_mtx.h> UF_initialize( ...

  7. electron-vue构建桌面应用

    一.项目搭建 electron-vue是vue-cli和electron结合的项目,比单独使用vue构建起的electron项目要方便很多. 1.初始化项目并运行 vue init simulated ...

  8. 知识整理:字符串hash

    字符串hash唯一用途是快速判断两字符串是否相等,但存在极小概率假阳性(本来不相等,但算法返回相等). 根本思想是把一个字符串转换为一个整数,要求相同的字符串,对应的这个整数相同,不同的字符串,对应的 ...

  9. Spring随笔-bean装配-自动装配

    Spring提供了三种装配方式 1.XML文件进行显式装配 2.java中进行显示装配 3.自动化装配 1.自动化装配的两种实现方式 1.组件扫描:Spring会自动发现应用上下文中创建的bean 2 ...

  10. 2019 牛客多校第一场 E ABBA

    题目链接:https://ac.nowcoder.com/acm/contest/881/E 题目大意 问有多少个由 (n + m) 个 ‘A’ 和 (n + m) 个 ‘B’,组成的字符串能被分割成 ...