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

代码:

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<queue>
  6. #include<stack>
  7. #include<set>
  8. #include<vector>
  9. #include<map>
  10. #include<cmath>
  11. const int maxn=1e5+;
  12. typedef long long ll;
  13. using namespace std;
  14. char str[];
  15. int main()
  16. {
  17. int T;
  18. cin>>T;
  19. int b;
  20. int cnt=;
  21. while(T--)
  22. {
  23. scanf("%s",str);
  24. scanf("%d",&b);
  25. if(b<)
  26. b=-b;
  27. int len=strlen(str);
  28. ll ans=;
  29. for(int t=;t<len;t++)
  30. {
  31. if(str[t]>=''&&str[t]<='')
  32. {
  33. ans=((ans*)+(str[t]-''))%b;
  34. }
  35. else
  36. {
  37. continue;
  38. }
  39. }
  40. printf("Case %d: ",cnt++);
  41. if(ans==)
  42. {
  43. puts("divisible");
  44. }
  45. else
  46. {
  47. puts("not divisible");
  48. }
  49. }
  50. return ;
  51. }
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class Main
  5. {
  6. public static void main(String[] args) {
  7. Scanner sc=new Scanner(System.in);
  8. int T;
  9. int cnt=1;
  10. T=sc.nextInt();
  11. while(T>=0)
  12. {
  13. BigInteger a,b,c;
  14. a=sc.nextBigInteger();
  15. b=sc.nextBigInteger();
  16. a=a.abs();
  17. b=b.abs();
  18.  
  19. System.out.print("Case "+cnt+":");
  20. if(a.remainder(b).equals(BigInteger.ZERO))
  21. {
  22. System.out.println(" divisible");
  23. }
  24. else
  25. {
  26. System.out.println(" not divisible");
  27. }
  28. T--;
  29. cnt++;
  30. }
  31.  
  32. }
  33.  
  34. }
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6. public static void main(String[] args) {
  7. // TODO Auto-generated method stub
  8. Scanner sc=new Scanner(System.in);
  9. int T;
  10. int cnt=1;
  11. T=sc.nextInt();
  12. while(T>=0)
  13. {
  14. BigInteger a,b,c;
  15.  
  16. a=sc.nextBigInteger();
  17. b=sc.nextBigInteger();
  18. a=a.abs();
  19. b=b.abs();
  20. System.out.print("Case "+cnt+":");
  21.  
  22. if(a.gcd(b).equals(b))
  23. {
  24. System.out.println(" divisible");
  25. }
  26. else
  27. {
  28. System.out.println(" not divisible");
  29. }
  30. T--;
  31. cnt++;
  32. }
  33.  
  34. }
  35.  
  36. }

LightOJ - 1214-Large Division(c++取模 + java的两种写法)的更多相关文章

  1. LightOJ 1214 Large Division

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

  2. LightOJ 1214 Large Division 水题

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

  3. java路径两种写法"/"和"\\"

    String path="D:\\新建文件夹\\2.png"; File file=new File(path); System.out.println(file.exists() ...

  4. LightOJ1214 Large Division —— 大数求模

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

  5. light oj 1214 - Large Division

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

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

  7. java中两种类型变量

    Java中有两种类型的变量,一种是对象类型,另一种是基础类型(primitive type). 对象类型普遍采用引用的方式,比如 List a = new ArrayList(); List b = ...

  8. JAVA 中两种判断输入的是否是数字的方法__正则化_

    JAVA 中两种判断输入的是否是数字的方法 package t0806; import java.io.*; import java.util.regex.*; public class zhengz ...

  9. Java中两种实现多线程方式的对比分析

    本文转载自:http://www.linuxidc.com/Linux/2013-12/93690.htm#0-tsina-1-14812-397232819ff9a47a7b7e80a40613cf ...

随机推荐

  1. Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependen

    Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependen ...

  2. 正确认识springcloud的作用。分布式从了解架构到springcloud支撑

    转载于 https://www.cnblogs.com/williamjie/p/9369681.html 基于springCloud的分布式架构体系   Spring Cloud作为一套微服务治理的 ...

  3. C#LeetCode刷题之#389-找不同(Find the Difference)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4062 访问. 给定两个字符串 s 和 t,它们只包含小写字母. ...

  4. 《闲扯Redis十》Redis 跳跃表的结构实现

    一.前言 Redis 提供了5种数据类型:String(字符串).Hash(哈希).List(列表).Set(集合).Zset(有序集合),理解每种数据类型的特点对于redis的开发和运维非常重要. ...

  5. BLE MESH 学习[1] - ESP32 篇

    BLE MESH 学习 BLE MESH 是一种蓝牙(n:m)组网的技术. 本篇先介绍 BLE MESH 到使用 ESP32 的官方示例对其进行学习讲解. 后面会进一步学习 SIG 的 BLE MES ...

  6. 神经网络实现fashion数据集

    import tensorflow as tf import numpy as np fashion=tf.keras.datasets.fashion_mnist (x_train,y_train) ...

  7. Python 函数为什么会默认返回 None?

    Python 有一项默认的做法,很多编程语言都没有--它的所有函数都会有一个返回值,不管你有没有写 return 语句. 本文出自"Python为什么"系列,在正式开始之前,我们就 ...

  8. three.js 利用uv和ThreeBSP制作一个快递柜

    最近有three网友,问我要不要学习blender,其实我感觉学习一下也无妨,不过花大量时间精通,尚可不必,术业有专攻给别人留一条路吧,哈哈.那我我们就是用ThreeBSP和uv贴图的知识来制作一个定 ...

  9. 如何校验内存数据的一致性,DynamicExpresso 算是帮上大忙了

    一:背景 1. 讲故事 记的在上一家公司做全内存项目的时候,因为一些关键表会在程序 startup 的时候全量灌入到内存中,但随着时间的推移,内存和数据库的同步偶尔会出现数据差异的情况,伴随着就是运营 ...

  10. exe调用DLL的方式

    假设被调用的DLL存在一个导出函数,原型如下: void printN(int); 三种方式从DLL导入导出函数 生成DLL时使用模块定义 (.def) 文件 在主应用程序的函数定义中使用关键字__d ...