加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

hdu 1212 Big Number(大数取模)

发布时间:2020-12-14 03:28:29 所属栏目:大数据 来源:网络整理
导读:原理: (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 #includestdio.h#includeiostream#i

原理:

(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("%dn",t);
	}
	return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读