Light oj 1214-Large Division (同余定理)

时间:2021-08-05 16:13:01

题目链接:http://lightoj.com/volume_showproblem.php?problem=1214

题意很好懂,同余定理的运用,要是A数被B数整除,那么A%B等于0。而A很大,那我就把A的每一位拆开,比如A是2341,那么2341=2000+300+40+1,然后你懂的...

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
char str[];
int main()
{
int t;
long long n;
cin >> t;
for(int ca = ; ca <= t ; ca++) {
cin >> str >> n;
int len = strlen(str);
long long temp = , begin = ;
if(str[] == '-')
begin++;
for(int i = begin ; i < len ; i++) {
temp = (temp * % n + (str[i] - '')) % n;
}
cout << "Case " << ca << ": ";
if(!temp)
cout << "divisible\n";
else
cout << "not divisible\n";
}
}