Big numbertime limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 4594 accepted submission (s): 3175
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
Use the same remainder theorem: (a + B) % C = (a % C + B % C) % C = (a + B % C) % C; Appendix: (A * B) % C = (a % C * B % C) % C;
#include <stdio.h>#define maxn 1002char str[maxn];int main(){ int m, ans, i; while(scanf("%s%d", str, &m) != EOF){ ans = 0; for(i = 0; str[i]; ++i){ ans = (ans * 10 + (str[i] - '0') % m) %m; } printf("%d\n", ans); } return 0;}
Hdu1212 big number [same theorem]