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

题意:给出两个数a, b,问能否被b整除。

题解:基础数论。简单的同余定理应用,将a作为字串储存,相当于每x位(和b同位)模b一次,得到余数时相当于将这个区间改写成这个余数,移动区间继续运算。最终余数为零时代表可以被整除,非零则否。

补充:其实可以想成这样,三位数就是百进制,四位数就是千进制的同余定理。

 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#define ll long long
using namespace std; char a[];
int main()
{
int T, x, s;
ll t, b;
scanf("%d", &T);
for(int i=; i<=T; i++)
{
scanf("%s %lld", a, &b);
x=strlen(a);
if(a[]=='-')//注意负数变正
{
s=;
t=a[]-'';
}
else
{
s=;
t=a[]-'';
}
t=t%abs(b);
for(int j=s; j<x; j++)
{
t=(t*+a[j]-'')%abs(b); //同余定理的应用
} if(t==)
{
printf("Case %d: divisible\n", i);
}
else
printf("Case %d: not divisible\n", i); } }

LightOJ1214 Large Division 基础数论+同余定理的更多相关文章

  1. LightOJ1214 Large Division

    /* LightOJ1214 Large Division http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1 ...

  2. 51nod 1433 0和5【数论/九余定理】

    1433 0和5 题目来源: CodeForces 基准时间限制:1 秒 空间限制:131072 KB 分值: 10 难度:2级算法题  收藏  关注 小K手中有n张牌,每张牌上有一个一位数的数,这个 ...

  3. LightOJ1214 Large Division —— 大数求模

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

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

  5. FZU 1057 a^b 【数论/九余定理】

    Accept: 1164    Submit: 3722Time Limit: 1000 mSec    Memory Limit : 32768 KB Problem Description 对于任 ...

  6. K - Large Division 判断a是否是b的倍数。 a (-10^200 ≤ a ≤ 10^200) and b (|b| > 0, b fits into a 32 bit signed integer). 思路:取余;

    /** 题目:K - Large Division 链接:https://vjudge.net/contest/154246#problem/K 题意:判断a是否是b的倍数. a (-10^200 ≤ ...

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

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

  8. Light oj 1214-Large Division (同余定理)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1214 题意很好懂,同余定理的运用,要是A数被B数整除,那么A%B等于0.而A很大,那我 ...

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

随机推荐

  1. emmmmmm

    211606342杨艺勇 211606379王熙航 单元测试 对每一个代码块进行测试,返回测试结果并和预期结果进行比对 对源代码进行相应的重构,以适应测试代码的调用,且不影响源代码的正常运行 通过与构 ...

  2. oracle数据库 expdp/impdp 和 exp/imp

    --EXPDP导出,需要系统用户权限,一般不使用--sqlplus--1.创建dmp导出逻辑目录 create directory 目录名 as '目录路径' create directory exp ...

  3. Windows 10 系统下Python环境的搭建与配置

    1. 在https://www.python.org/downloads/release/python-352/网站上下载python版本 2. 配置环境 右击计算机属性,然后选择高级系统设置 3.  ...

  4. Alpha冲刺——第六天

    Alpha第六天 听说 031502543 周龙荣(队长) 031502615 李家鹏 031502632 伍晨薇 031502637 张柽 031502639 郑秦 1.前言 任务分配是VV.ZQ. ...

  5. HDU 5666 Segment 数论+大数

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5666 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  6. C++ Primer Plus学习:第九章

    C++第九章:内存模型与名称空间 C++在内存中存储数据方面提供了多种选择.可直接选择保留在内存中的时间长度(存储持续性)以及程序哪一部分可以访问数据(作用域和链接)等. 单独编译 程序分为三个部分: ...

  7. Scrum 项目准备3.0

    SCRUM 流程的步骤2: Spring 计划 1. 确保product backlog井然有序.(参考示例图1) 2. Sprint周期,一个冲刺周期,长度定为两周,本学期还有三个冲刺周期. Spr ...

  8. PAT 甲级 1035 Password

    https://pintia.cn/problem-sets/994805342720868352/problems/994805454989803520 To prepare for PAT, th ...

  9. linux学习笔记4

    查看当前系统还有哪些用户 who 字符计数 wc -l(line) 可以统计有多少行 -w(word) 可以统计有多少个单词 -c(character) 可以统计有多少个字符  切个字符 - 排序 l ...

  10. centos中apache自用常用额外配置记录(xwamp)

    xwamp套件中apache配置,记录下,以免忘记. 配置路径 ${wwwroot_dir}/conf/httpd.conf 配置内容 <ifmodule mod_deflate.c> D ...