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 }

最新文章

  1. jquery 中jsonp的实现原理
  2. MVC基础知识 &ndash; 2.新语法
  3. spring和mybatis集成,自动生成model、mapper,增加mybatis分页功能
  4. Linux SHELL脚本
  5. H5不能少的功能-滑动分页
  6. ASP.NET WEB API 初探
  7. css中单位px,em,rem的区别
  8. struts1与strut2的区别
  9. nomasp 博客导读:Android、UWP、Algorithm、Lisp(找工作中……
  10. Eclipse Maven构建Spring MVC项目
  11. 中兴电信光纤猫F450获取管理员密码方法
  12. BeanUtils属性
  13. ural1553 Caves and Tunnels
  14. linux守护进程、SIGHUP与nohup详解
  15. C# 程序集安装与卸载
  16. 如何用java实现一个p2p种子搜索(1)-概念
  17. Egret的容器--删除对象,遮罩
  18. Self-Introduce
  19. http协议解析过程
  20. jQuery3 slim版本和普通版本区别,如何选择?

热门文章

  1. Vue.js 监听属性
  2. canvas 压缩图片上传
  3. jq-demo-点击选择(英雄联盟)
  4. Python加密模块
  5. python 打印出水仙花数
  6. 泛型(Generic)方法(函数,算法)
  7. NX二次开发-UFUN将实体放入STL文件中函数UF_STD_put_solid_in_stl_file
  8. gnome/KDE安装,gnome出现问题,重新安装nvdia驱动, Linux(CentOS7) NVIDIA GeForece GTX 745 显卡驱动
  9. 全面解读PHP面试
  10. 1-电脑C盘(系统盘)清理