hdu 1212 Big Number(大数取模)

原理:

(a * b) % c = ((a % c) * (b % c)) % c
(a + b) % c = ((a % c) + (b % c)) % c
10000位大的数字可以分开算:
比如:
m=123
123 = (1*10 + 2)*10 + 3
m%n = 123%n = (((1%n * 10%n + 2%n)%n * 10%n) % n + 3%n)%n

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main(){
	int t,n,i;
	char s[1010];
	while(~scanf("%s%d",s,&n)){
		for(t=i=0;s[i];i++){
			t=(t*10+s[i]-'0')%n;
		}
		printf("%d\n",t);
	}
	return 0;
}


你可能感兴趣的:(hdu 1212 Big Number(大数取模))