题目链接:https://vjudge.net/problem/LightOJ-1214

1214 - Large Division
Time Limit: 1 second(s) Memory Limit: 32 MB

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 <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int MAXM = 1e5+;
const int MAXN = 5e5+; char a[];
int b; int main()
{
int T, kase = ;
scanf("%d", &T);
while(T--)
{
scanf("%s%d", a, &b);
int len = strlen(a);
b = abs(b);
LL s = ;
for(int i = (a[]=='-'); i<len; i++)
{
s *= , s += a[i] - '';
s %= b;
}
printf("Case %d: %s\n", ++kase, s?"not divisible":"divisible");
}
}

LightOJ1214 Large Division —— 大数求模的更多相关文章

  1. Large Division (大数求余)

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

  2. LightOJ1214 Large Division

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

  3. 大数求模 sicily 1020

        Search

  4. light oj 1214 - Large Division 大数除法

    1214 - Large Division Given two integers, a and b, you should check whether a is divisible by b or n ...

  5. LightOJ1214 Large Division 基础数论+同余定理

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

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

  7. [18/12/3]蓝桥杯 练习系统 入门级别 Fibonacci数列求模问题 题解思路

    前言略. 看到这个题目本来应该很高兴的,因为什么,因为太TM的基础了啊! 可是当你用常规方法尝试提交OJ时你会发现..hhh...运行超时..(开心地摇起了呆毛 //Fibonacci数列递归一般问题 ...

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

  9. (POJ2635)The Embarrassed Cryptographer(大数取模)

    The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13041 Accep ...

随机推荐

  1. 遇到的cannot find module 'xxx' 问题

    昨天配置新项目的环境,明明都npm inatsll都安装了,再次运行的时候一直报错,缺少模块.我以为就一个没安装上,就手动npm install -g 'xxx' :结果一个装好了,又继续蹦出cann ...

  2. 华硕win7安装ubuntu14.04.02注意事项

    一.win7下划出给ubuntu系统的分区 1.win7自带分磁盘的工具,只需要压缩步骤即可,不需要继续分盘符格式化等操作 win7下为绿色 安装时为free space 二.制作启动盘并安装注意事项 ...

  3. 同源策略Same-origin policy

     同源策略Same-origin policy 同源策略Same-origin policy是Web应用的一种安全基础策略.它规定同一源中,页面包含的脚本可以访问该源下的其他页面的数据.只有当网址中的 ...

  4. 邁向IT專家成功之路的三十則鐵律 鐵律十一:IT人應對之道-靈活

    身為一位優秀的IT專家,不能夠只是在技術面的應對能力強,而必須是在人事的應對能力上也要能夠靈活與彈性,否則就算一天給你48小時,你也會把自己的身心弄垮,再強的專業.技術.能力也會瞬間化為泡影. 坦白說 ...

  5. openfire Android学习(三)----会议室创建、加入以及查询会议室中所有成员等

    openfire 中的会议室不像QQ群一样,不能保存那些离线用户,加入会议室后,一旦断开连接,就会离开会议室. 虽然如此,但如果要实现也不是不可能,我们可以自己做后台来保存,有兴趣的可以去试着实现一下 ...

  6. 解决mac osx下pip安装ipython权限的问题

    1 pip install ipython --user -U 下面是pip install gevent的错误提示, 又是 Operation not permitted …   1 2 3 4 5 ...

  7. squirrelsql安装

    官网下载安装,第一次安装mac上,失败,后续重启mac看下.重启完后,还是起不来,估计和某些环境冲突,或者缺少环境 使用squirrelsql如何连接hive? http://lxw1234.com/ ...

  8. php 的$_POST 和$_REQUEST的区别

    发现$_POST 没数据,而$_REQUEST 有数据 ----------------------------------------- https://stackoverflow.com/ques ...

  9. Unity开发规范(个人习惯,仅供參考)

    近期整理了一下unity里的文件夹使用和脚本上的一些规范,这个看个人习惯,仅供參考 1.unity中的Project文件夹      总体文件夹大致例如以下:            按资源种类分目录. ...

  10. git 强制覆盖,分支合并

    强制合并 git fetch --all && git reset --hard origin/master && git pull 合并代码 git commit - ...