Light Oj 1214 大数整除

Large Division

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu

Submit

Status

Practice

LightOJ 1214

Description

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

6

101 101

0 67

-101 101

7678123668327637674887634 101

11010000000000000000 256

-202202202202000202202202 -101

Sample Output

Case 1: divisible

Case 2: divisible

Case 3: divisible

Case 4: not divisible

Case 5: divisible

Case 6: divisible

<span style="color:#6600cc;">/*******************************************

     author   :   Grant Yuan
     time     :   2014.8.7
     algorithm:   大数整除
     source   :   Light Oj 1214
     explain  :  从ans初始化为0,最低位开始ans=(ans+s[i]-'0')%b;
                  计算到最后,如果ans 等于0,可以整除;
                  否则,不可以整除;

**********************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define INF 0x3fffffff

using namespace std;

char s[2000002];
int b;
long long ans;
int t;

int main()
{
    scanf("%d",&t);
    for(int i=1;i<=t;i++)
    {    memset(s,0,sizeof(s));
        scanf("%s%d",&s,&b);
        if(b<0) b=-b;
        int l=strlen(s);
        ans=0;
        for(int j=0;j<l;j++)
        {
            if(s[j]=='-') continue;
            ans=(ans*10+(s[j]-'0'))%b;
        }
        if(ans==0)
            printf("Case %d: divisible\n",i);
        else
            printf("Case %d: not divisible\n",i);
    }
    return 0;
}
</span>

Light Oj 1214 大数整除

时间: 2024-08-28 17:47:42

Light Oj 1214 大数整除的相关文章

light oj 1214 - Large Division 大数除法

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 in

light oj 1214 - Large Division

1214 - Large Division   PDF (English) Statistics Forum 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

Light OJ 1214

简单大数模拟题: #include<bits/stdc++.h> using namespace std; typedef long long ll; string Num; vector<ll> Big; ll MOD(vector<ll> Big, ll m) { ll ret = 0; for(int i = 0; i < Big.size(); ++i) { ret = ret * 10 + Big[i]; ret = ret % m; } return

light oj 1236 【大数分解】

给定一个大数,分解质因数,每个质因子的个数为e1,e2,e3,--em, 则结果为((1+2*e1)*(1+2*e2)--(1+2*em)+1)/2. //light oj 1236 大数分解素因子 #include <stdio.h> #include <iostream> #include <string.h> #include <algorithm> #include <math.h> #include <ctype.h> #i

[2016-04-21][light]OJ[1234][Harmonic Number]

时间:2016-04-21 22:18:26 星期四 题目编号:[2016-04-21][light]OJ[1234][Harmonic Number] 题目大意:求∑nk=11kn∈(1,108),精确到10?8求∑k=1n1kn∈(1,108),精确到10?8 分析: 想法是打表,然后输出,但是直接打表会爆内存 解决办法,就是每隔100个来打表,节省1100的空间,然后从那个值开始计算到当前值解决办法,就是每隔100个来打表,节省1100的空间,然后从那个值开始计算到当前值 对应的整百就是n

Light OJ 1411 Rip Van Winkle`s Code 线段树成段更新

题目来源:Light OJ 1411 Rip Van Winkle`s Code 题意:3中操作 1种查询 求区间和 其中每次可以把一段区间从左到右加上1,2,3,...或者从右到左加上...3,2,1 或者把某个区间的数都置为v 思路:我是加了6个域 add是这段区间每个数都要加上add  add是这么来的 对与123456...这个等差数列 可能要分为2个区间 那么我就分成123和123 两个右边的等差数列每个数还应该加上3 所以右区间add加3 v是这个区间都要置为v 他的优先级最高 b是

Light OJ 1168 Wishing Snake 强连通缩点+哈密顿通路

题目来源:Light OJ 1168 Wishing Snake 题意:有点难看懂题意 看了一个小时再加别人的代码才懂意思 从0开始 输入的那些每一对u v 都要经过 就是从0到到达那些点 思路:首先缩点 每一个强连通分量里面的点都是可达的 缩点后的图是有向无环图 如果从0这个强连通分量可以出去到2个强连通分量 那么这两个强连通分量是不可能相互可达 所以可行的方案就是所有的强连通分量连成一线 一个一个串起来 除了第一个 出度是1入度是0和最后一个出度是0入度是1 其他都是入度等于出度是1 特判只

Jan&#39;s light oj 01--二分搜索篇

碰到的一般题型:1.准确值二分查找,或者三分查找(类似二次函数的模型). 2.与计算几何相结合答案精度要求比较高的二分查找,有时与圆有关系时需要用到反三角函数利用 角度解题. 3.不好直接求解的一类计数问题,利用二分直接枚举可能的结果,再检查是否符合题目要求. 4.区间求解,即利用两次二分分别查找有序序列左右上下限,再求差算出总个数. 题型知识补充: 1. 三分的一般写法: 1 double thfind(double left,double right) 2 { 3 double midmid

light oj 1422 - Halloween Costumes (区间dp)

1422 - Halloween Costumes PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Gappu has a very busy weekend ahead of him. Because, next weekend is Halloween, and he is planning to attend as many parties as he can. Since it's Ha