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. xtrabackup备份还原mariadb数据库

    一.xtrabackup 简介 xtrabackup 是由percona公司开源免费的数据库热备软件,它能对InnoDB数据库和XtraDB存储引擎的数据库非阻塞地备份,对于myisam的备份同样需要 ...

  2. Java入门 - 高级教程 - 04.序列化

    原文地址:http://www.work100.net/training/java-serialization.html 更多教程:光束云 - 免费课程 序列化 序号 文内章节 视频 1 概述 2 序 ...

  3. 高通量计算框架HTCondor(二)——环境配置

    目录 1. 概述 2. 安装 3. 结果 4. 相关 1. 概述 HTCondor是开源跨平台的分布式计算框架,在其官网上直接提供了源代码和Windows.Linux以及MacOS的安装包.因为平台限 ...

  4. Linux下Tomcat,mysql安装包及教程整合,

      前段时间孔老师给了一个虚拟机,自己瞎捣鼓,装了Tomcat和mysql,捣鼓了好几天,把一些安装包和试过还不错的博客整理出来:  老师给的已经装好了Linux系统和JDK. Tomcat9安装包 ...

  5. 编程基础系列--之--浅谈List、Set、Map和泛型(一)——单列集合

    之前在学习Java时对于泛型,集合的理解一直模模糊糊,随着时间的推移,对泛型和集合有了一些浅显的认知,打算写出来巩固一下,也希望各位大佬能指出理解不当之处,万分感谢!!! 在Java语言中,集合分为两 ...

  6. (转)GET来的漏洞

    转自呆子不开口在wooyun知识库的文章 0x00 前言 这篇文章主要讲目前互联网上get方法被不规范使用带来的一些安全漏洞.其中重点会讲get请求在账号登陆体系中被滥用的场景和攻击方式. 0x01 ...

  7. 管道模式 pipe

    先放一个图,预则立嘛

  8. [白话解析] 深入浅出支持向量机(SVM)之核函数

    [白话解析] 深入浅出支持向量机(SVM)之核函数 0x00 摘要 本文在少用数学公式的情况下,尽量仅依靠感性直觉的思考来讲解支持向量机中的核函数概念,并且给大家虚构了一个水浒传的例子来做进一步的通俗 ...

  9. JavaScript学习之路1

    1. 变量类型只有var var money=5; var house="big house"; 示例如下 <!DOCTYPE html> <html> & ...

  10. Qt下Armadillo矩阵函数库的添加

    其实本文严格说只能算VS2013添加Armadillo教程,因为为了省事,用的是VS2013编译器版本的Qt,Armadillo也直接用了自带例子中的blas_win64_MT.dll.blas_wi ...