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

HDU-#1212 Big Number(大数取模)

发布时间:2020-12-14 03:04:29 所属栏目:大数据 来源:网络整理
导读:? ? ? 题目大意:大整数取模问题。 ? ? ? 解题思路:将大数转化为字符串处理,然后问题可以等价于各个位数上的分别取模。详见code。 ? ? ? 题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1212 ? ? ? code: #include iostream#include cstdio#includ

? ? ? 题目大意:大整数取模问题。

? ? ? 解题思路:将大数转化为字符串处理,然后问题可以等价于各个位数上的分别取模。详见code。

? ? ? 题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1212

? ? ? code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int MAXN = 1000+10;
char n[MAXN]; //大数一般都转化为字符串处理
int m;

int main(){
    while(scanf("%s%d",n,&m)!=EOF){
        int len=strlen(n);
        int ans=0;
        for(int i=0;i<len;i++) //每步取模:1234=((1*10+2)*10+3)*10+4
            ans=(int)(((long long)ans*10+(n[i]-'0'))%m); //防止乘法溢出,转化为longlong
        printf("%dn",ans);
    }
    return 0;
}

(编辑:李大同)

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

    推荐文章
      热点阅读