题目:

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 (-10^200 ≤ a ≤ 10^200) 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为负数的情况。

代码:

#include <iostream>
#include <cstring>
using namespace std;
char a[100000];
int main()
{long long t,i,k,b,n,h;cin>>t;h=1;while(t--){cin>>a;cin>>b;if(b<0) b=-b;n=strlen(a);if(a[0]=='-'){for(i=0;i<n-1;i++){a[i]=a[i+1];}n--;}k=0;for(i=0;i<n;i++){k=(k*10+a[i]-'0')%b;}cout<<"Case "<<h++<<": ";if(!k) cout<<"divisible"<<endl;else cout<<"not divisible"<<endl;}return 0;
}

Light OJ 1214 Large Division (大数取模)相关推荐

  1. POJ-2635 The Embarrassed Cryptographer 大数取模

    题意是给定一个大数,这个数是由两个素数相乘得到的,现在问你这个大数的分解是否存在一个素数小于给定的数.由于这个给定的数L小于10^6,所以我们就可以打表到10^6,最好打的大一点(比10^6大的最小的 ...

  2. 大数取模运算,快速幂取模运算

    1.快速幂取模 http://www.cnblogs.com/yinger/archive/2011/06/08/2075043.html 快速幂取模就是在O(logn)内求出a^n mod b的值. ...

  3. hdu1226超级密码【数字广搜+大数取模】

    第一眼看到这个题就想到了poj3126Prime Path (题解地址 果然还是自己做出来的题印象深) 但是很不幸的是 ,这个题一个大数取模就把我整蒙了orz 其他的真没啥区别,还多了一个第一位不能是 ...

  4. [2016湘潭邀请赛 A. 2016] 大数取模+循环节

    [2016湘潭邀请赛 A. 2016] 大数取模+循环节 1. 题目链接 XTU OnlineJudge : [2016湘潭邀请赛 A. 2016] 2. 题意描述 [图片看不清可以放大.] 给定一个 ...

  5. 【蓝桥杯】2017初赛 外星日历/大数取模

    题目描述 某星系深处发现了文明遗迹.他们的计数也是用十进制. 他们的文明也有日历.日历只有天数,没有年.月的概念. 有趣的是,他们也使用了类似"星期"的概念,只不过他们的一个星期包 ...

  6. zcmu-1934(卡特兰数大数取模(逆元))

    1934: ly的二叉树 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 42  Solved: 9 [Submit][Status][Web Boar ...

  7. 【北航oj】(线段树取模运算)

    题干: https://buaacoding.cn/contest-ng/index.html#/334/problems K wjj 的自动售货机 时间限制:1000ms   内存限制:131072 ...

  8. python快速幂算法解决大数取模

    1.前置性质 模运算的性质 [(a mod n)×(b mod n)] mod n = (a×b) mod n 指数可以拆分成二进制的形式,如9拆分成 1001 根据二进制的计算,1001 = ((1 ...

  9. 2018年东北农业大学春季校赛 K wyh的数列【数论/斐波那契数列大数取模/循环节】...

    链接:https://www.nowcoder.com/acm/contest/93/K 来源:牛客网 题目描述 wyh学长特别喜欢斐波那契数列,F(0)=0,F(1)=1,F(n)=F(n-1)+F ...

最新文章

  1. 基数排序算法(基于Java实现)
  2. 算法--------俄罗斯套娃信封问题(Java版本)
  3. EC2 WordPress 移动目录
  4. the largest issue in management
  5. 作者:刘建楠(1963-),男,就职于中国石油天然气股份有限公司庆阳石化分公司...
  6. 基于or1200最小sopc系统搭建(一)--搭建及仿真(DE2,DE2-70)
  7. C 语言实例 - 判断三边能否构成三角形
  8. Linux 简单的shell实现
  9. Javascript实现子窗口向父窗口传值(转)
  10. 玩转Android---组件篇---Broadcast Receiver(广播接收器)
  11. android 反编译 dex2jar,Android反编译教程:apktool,dex2jar的使用
  12. 这三个方法让你实现电脑截图转文字的操作
  13. Homebrew 安装以及更新源替换
  14. python画美女代码_3分钟画字符画跟女神表白,利用python字符串、列表方法
  15. 使用原始武器的现代战争
  16. Metal每日分享,调整胶片颗粒感滤镜效果
  17. Java API VIII
  18. powerquery分组_Power Query系列 - 排序Ranking
  19. 使用word2vec对新浪微博进行情感分析
  20. 安霸s2l 的IPC项目--进展2

热门文章

  1. libpcap抓取数据包
  2. 兰山天书(贺兰山岩画)
  3. CCS v5 无法启动解决办法及Launchpad仿真器电脑无法识别解决方法
  4. jQuery Mobile 笔记(1)- jQuery Mobile页面结构
  5. [转] 书摘及访谈:Aptana RadRails,一个Rails的集成开发环境
  6. JavaScript 读取、写入Txt文档
  7. jBPM3.12用户指南中文翻译----第二章 起步
  8. MQTT数据处理之从tcp连接获取数据过程
  9. 决策树(Decision Tree)和随机森林
  10. Bech32编码 (1)产生背景