Light oj 1214-Large Division (同余定理)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1214
题意很好懂,同余定理的运用,要是A数被B数整除,那么A%B等于0。而A很大,那我就把A的每一位拆开,比如A是2341,那么2341=2000+300+40+1,然后你懂的...
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 char str[2005]; 6 int main() 7 { 8 int t; 9 long long n; 10 cin >> t; 11 for(int ca = 1 ; ca <= t ; ca++) { 12 cin >> str >> n; 13 int len = strlen(str); 14 long long temp = 0 , begin = 0; 15 if(str[0] == '-') 16 begin++; 17 for(int i = begin ; i < len ; i++) { 18 temp = (temp * 10 % n + (str[i] - '0')) % n; 19 } 20 cout << "Case " << ca << ": "; 21 if(!temp) 22 cout << "divisible\n"; 23 else 24 cout << "not divisible\n"; 25 } 26 }