Big number
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 4789 accepted submission (s): 3329
Problem descriptionas we know, big number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to calculate a mod B.
To make the problem easier, I promise that B will be smaller than 100000.
Is it too hard? No, I work it out in 10 minutes, and my program contains less than 25 lines.
Inputthe input contains several test cases. each test case consists of two positive integers A and B. the length of a will not exceed 1000, and B will be smaller than 100000. process to the end of file.
Outputfor each test case, You Have To ouput the result of a mod B.
Sample Input
2 312 7152455856554521 3250
Sample output
251521
Authorignatius. L
Source hangdian ACM provincial training team trials
Meaning: Big integer modulo operation, similar to integer division (hand calculation), for example, 512% 10, we have 51% 10 = 1, and then 1*10 + 2 = 12, in 12% 10 = 2, it is over;
AC code:
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>using namespace std;typedef long long ll;int main(){ char s[1100]; int mod,len; while(cin>>s>>mod) { ll sum = 0; len = strlen(s); for(int i = 0; i < len; i++) { sum = (sum * 10 + s[i] - '0') % mod; } cout<<sum<<endl; } return 0;}
Big number (Modulo of big integers)