您的位置:首页 > 其它

hdu 1212 Big Number(大数取模)

2014-07-24 13:57 162 查看
原理:

(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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: