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. python 生成器 yield语句

    生成器就是一个返回迭代器(iterator)的函数. 包含了 yield 的函数,就是一个生成器. 生成器每使用yield语句产生一个值,函数就会被冻结(暂停执行),被唤醒后(即再次调用)接着上次执行 ...

  2. [组合数学][多项式][拉格朗日插值]count

    源自 ditoly 大爷的 FJ 省队集训课件 Statement 有 \(m\) 个正整数变量,求有多少种取值方案 使得所有变量的和不超过 \(S\) 并且前 \(n\) 个变量的值都不超过 \(t ...

  3. 高精度算法(C/C++)

    高精度算法 (C/C++) 做ACM题的时候,经常遇到大数的加减乘除,乘幂,阶乘的计算,这时给定的数据类型往往不够表示最后结果,这时就需要用到高精度算法.高精度算法的本质是把大数拆成若干固定长度的块, ...

  4. 最强PostMan使用教程

    最近需要测试产品中的REST API,无意中发现了PostMan这个chrome插件,把玩了一下,发现postman秉承了一贯以来google工具强大,易用的特质.独乐乐不如众乐乐,特此共享出来给大伙 ...

  5. NOI4.6 最小新整数——切山游戏

    描述 给定一个十进制正整数n(0 < n < 1000000000),每个数位上数字均不为0.n的位数为m. 现在从m位中删除k位(0<k < m),求生成的新整数最小为多少? ...

  6. 第二次团队作业-需求分析(By七个小矮人)

    第二次团队作业-需求分析 一.格式描述 这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/GeographicInformationScience/ 这个作 ...

  7. 【WPF学习】第二十三章 列表控件

    WPF提供了许多封装项的集合的控件,本章介绍简单的ListBox和ComboBox控件,后续哈会介绍更特殊的控件,如ListView.TreeView和ToolBar控件.所有这些控件都继承自Item ...

  8. 从桌面到Web - 领域模型的创建

    天佑武汉,天佑中国.这次为全国人民作出巨大牺牲的武汉人是坚强和担当的. 这次疫情期间的自我隔离的一个副作用是第一次享受这个超长假期,本来想好好学习一下Web技术的,但家里的唯一一台计算机被占用,不得已 ...

  9. CTF--HTTP服务--暴力破解

    开门见山 1. 扫描靶机ip,发现PCS 192.168.1.103 2. 用nmap扫描靶机开放服务和服务版本 3. 再扫描全部信息 4. 用nikto探测敏感文件 5. 打开敏感网页发掘信息 6. ...

  10. SQLException:The server time zone

    报错信息如下: java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represen ...