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

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

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
char a[250];
ll b,t,ans;
int main()
{
    scanf("%d",&t);
    int k=t;
    while(t--)
    {
        scanf("%s %lld",a,&b);
        b=abs(b);
        printf("Case %d: ",k-t);
        ans=0;
        for(int i=0;i<strlen(a);i++)
        {
            if(a[i]==‘-‘) continue;
            ans=ans*10+(a[i]-‘0‘);
            ans=ans%b;
            if(ans==0) {puts("divisible");goto end;}
        }
        puts("not divisible");
        end:;
    }
    return 0;
}
时间: 2024-10-13 11:23:03

Large Division (大数求余)的相关文章

LightOJ 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 checkwhether a is divisible by b or not. We know that an integer ais divisible by an integer b if and only if the

POJ 2635 The Embarrassed Cryptographer(大数求余)

题意:给出一个大数,这个大数由两个素数相乘得到,让我们判断是否其中一个素数比L要小,如果两个都小,输出较小的那个. 分析:大数求余的方法:针对题目中的样例,143 11,我们可以这样算,1 % 11 = 1:      1×10 + 4 % 11 = 3:      3×10 + 3 % 11 = 0;我们可以把大数拆成小数去计算,同余膜定理保证了这个算法的这正确性,而且我们将进制进行一定的扩大也是正确的. 注意:素数打标需要优化,否则超时.   进制需要适当,100和1000都可以,10进制超

大数求余

1 /**2016中国大学生程序设计网络赛赛HDU 2 1001大数求余 3 */ 4 5 #include "iostream" 6 #include "cstdio" 7 #include "cstring" 8 using namespace std; 9 char s[100000002]; 10 int main() { 11 12 int t=1; 13 while(~scanf("%s", &s)) {

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

nyoj 803 A/B Problem(大数除小数&amp;&amp;大数求余小数)

这道题 也就是大数除或者求模小数,不过听说java处理大数很方便,可是java学的一塌糊涂..有心人用java做吧 奉上c语言代码: #include <stdio.h> #include <string.h> int main() { char a[1000],c[1000],ch; int b,i,j,r; while(scanf("%s %c %d",a,&ch,&b)!=EOF)//a是存贮大数,ch存贮运算符,b是小数 { r=0; i

POJ 2305大数求余

一开始是的想法是用减法代替除法,一直减到被减数小于减数,所得的被减数就是余数.为了方便编程,还在减法中对齐了被减数和减数的位数.但过程还是比较麻烦,会超时. 1 #include "stdafx.h" 2 #include<string> 3 #include<iostream> 4 using namespace std; 5 int b; 6 string decrease(string p, string cut) 7 { 8 int diff=p.siz

大数求余简单办法(水)

Prepared for New Acmer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7477    Accepted Submission(s): 2826 Problem Description 集训进行了将近2个礼拜,这段时间以恢复性训练为主,我一直在密切关注大家的训练情况,目前为止,对大家的表现相当满意,首先是绝大部分队员

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

http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一个数d去除,有相同的余数.d数学上的称谓为模.如a=6,b=1,d=5,则我们说a和b是模d同余的.因为他们都有相同的余数1. //// 数学上的记法为: a≡ b(mod d) 可以看出当n<d的时候,所有的n都对d同商,比如时钟上的小时数,都小于12,所以小时数都是模12的同商. 对于同余有三种

大数模拟——K - Large Division LightOJ - 1214

K - Large Division LightOJ - 1214 大数模拟,记得把符号去掉 1 #include <iostream> 2 #include <cstring> 3 #include <string> 4 #include <map> 5 #include <set> 6 #include <algorithm> 7 #include <fstream> 8 #include <cstdio>