1214 - 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

Output for Sample Input

6

101 101

0 67

-101 101

7678123668327637674887634 101

11010000000000000000 256

-202202202202000202202202 -101

Case 1: divisible

Case 2: divisible

Case 3: divisible

Case 4: not divisible

Case 5: divisible

Case 6: divisible

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#define N 1000010

using namespace std;
char ar[N];
int nu[N];
long long m;
void option()
{
long long x, y;
int j;
int i = 0;
int len = strlen(ar);
if(ar[0] == '-')
{
len--;
i = 1;///判断是否为负数,i为ar数组的起始下标。
}
for( j = 0; ar[j]; j++, i++)
nu[j] = ar[i] - '0';///将字符串转换为数字。

if(m < 0)
m = -m;

for(j = 0, y = 0; j < len; )
{
x = y;

while(x <= m && j < len)
{
x = x * 10 + nu[j];
j++;
}

y = x % m;
}

if(y)
printf("not divisible\n");
else
printf("divisible\n");
}
int main(void)
{
int T, cas;
scanf("%d", &T);
cas = 0;
while(T--)
{
cas++;
scanf("%s%lld", ar, &m);
printf("Case %d: ", cas);
option();
}
return 0;
}

light oj 1214 - Large Division 大数除法的更多相关文章

  1. light oj 1214 - Large Division

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

  2. LightOJ1214 Large Division —— 大数求模

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

  3. (大数 求余) 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 ...

  4. LightOJ 1214 Large Division

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

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

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

  6. LightOJ 1214 Large Division 水题

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

  7. Light OJ 1214

    简单大数模拟题: #include<bits/stdc++.h> using namespace std; typedef long long ll; string Num; vector ...

  8. L - Large Division (大数, 同余)

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

  9. Large Division (大数求余)

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

随机推荐

  1. .net生成荣誉证书

    参考:https://blog.csdn.net/ljk126wy/article/details/84299373 采用生成pdf 方式  效果如下: 用adobe acrobat 制作一个模板  ...

  2. python爬虫——urllib使用代理

    收到粉丝私信说urllib库的教程还没写,好吧,urllib是python自带的库,没requests用着方便.本来嘛,python之禅(import this自己看)就说过,精简,效率,方便也是大家 ...

  3. Python线程-死锁

    死锁产生的4个必要条件:    1.互斥:一个资源同一时刻只允许一个线程进行访问.    2.占有未释放:一个线程占有资源,且没有释放资源.    3.不可抢占:一个已经占有资源的线程无法抢占到其他线 ...

  4. 系列免费课程汇总(Java、单体应用、微服务、物联网、SaaS)

    概述 2020年春节尽在眼前,又忙碌了一年的你一定有很多收获:是升职加薪,还是收获爱情?是买房置业,还是新添人口? 我在2019年的最大收获是:我的第二枚千金诞生,使我顺利加入富豪行列! 新年伊始我们 ...

  5. 《ASP.NET Core 高性能系列》关于性能的闲聊

    一.通常的性能问题类型 让我们一起看看那些公共的性能问题,看看他们是或者不是.我们将了解到为什么我们常常在开发期间会错过这些问题.我们也会看看当我们考虑性能时语言的选择.延迟.带宽.计算等因素. 二. ...

  6. 域渗透之票据传递攻击(pass the ticket,ptt)

    票据传递攻击(PtT)是一种使用Kerberos票据代替明文密码或NTLM哈希的方法.PtT最常见的用途可能是使用黄金票据和白银票据,通过PtT访问主机相当简单. 1.ptt攻击的部分 就不是简单的N ...

  7. 【WPF学习】第十七章 键盘输入

    当用户按下键盘上的一个键时,就会发生一系列事件.下表根据他们的发生顺序列出了这些事件: 表 所有元素的键盘事件(按顺序) 键盘处理永远不会像上面看到的这么简单.一些控件可能会挂起这些事件中的某些事件, ...

  8. vwmare 十月第 1 弹

    step one 不管 是 ubuntu 还是 win vm tools 都是需要在虚拟的系统里面的去安装的. 这一点是相同的.

  9. MEF sample

    博客里介绍ntier 基于这个框架有一个叫WAF的示例项目. 看 waf(WPF Application Framework)里面这样有句 不是很懂, This page might help you ...

  10. 运用路由约束 使用属性路由 精通ASP-NET-MVC-5-弗瑞曼