数论(大数取模) - Large Division LightOJ - 1214
题意:
Input
开始会输入一个数字 T (≤ 525), 代表了样例数.
每个样例会给两个整数a (-10200 ≤ a ≤ 10200) and b (|b| > 0, b fits into a 32 bit signed integer). 数字不会包含前导零.
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<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
const int N=210;
char a[N];
int b,len;
bool check()
{
ll tmp=0;
for(int i=0,j;i<len;i++)
{
if(a[i]=='-') continue;
tmp=tmp*10+a[i]-'0';
if(tmp>=b) tmp%=b;
}
return tmp==0;
}
int main()
{
int T; cin>>T;
for(int t=1;t<=T;t++)
{
scanf("%s",a);
scanf("%d",&b);
len=strlen(a);
printf("Case %d: ",t);
if(check()) puts("divisible");
else puts("not divisible");
}
}