Problem Description

As 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.

Input

The 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.

Output

For each test case, you have to ouput the result of A mod B.

Sample Input

2 3
12 7
152455856554521 3250

Sample Output

2
5
1521

解题思路:这是一道大数取模的题目,运用到同余定理:(a+b)%c=(a%c+b%c)%c=(a+b%c)%c。

(a*b)%c=(a%c*b%c)%c。本质是模拟做除法运算,过程中只需保留余数即可!举个例子:572%7=((((5%7==5)*10+7==57)%7==1)*10+2==12)%7==5。

AC代码:

 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
string str;int mod, ans;
int main() {
while(cin >> str >> mod) {
ans = ;
for(int i = ; str[i]; ++i) ans = (ans * + (str[i] - '')) % mod;
cout << ans << endl;
}
return ;
}

题解报告:hdu 1212 Big Number(大数取模+同余定理)的更多相关文章

  1. HDU 1212 大整数的取模运算

    因为这里是MOD最大为100000 所以我将字符串看作5个一组,并记录后面跟了多少个100000 每次取5个数根据其数据进行取模更新 注意过程中 100000*100000会超int #include ...

  2. HDU 1212 Big Number 大数模小数

    http://acm.hdu.edu.cn/showproblem.php?pid=1212 题目大意: 给你一个长度不超过1000的大数A,还有一个不超过100000的B,让你快速求A % B. 什 ...

  3. ACM-ICPC 2018 焦作赛区网络预赛G Give Candies(隔板定理 + 小费马定理 + 大数取模,组合数求和)题解

    题意:给你n个东西,叫你把n分成任意段,这样的分法有几种(例如3:1 1 1,1 2,2 1,3 :所以3共有4种),n最多有1e5位,答案取模p = 1e9+7 思路:就是往n个东西中间插任意个板子 ...

  4. hdu2302(枚举,大数取模)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2303 题意:给出两个数k, l(4<= k <= 1e100, 2<=l<=1 ...

  5. (POJ2635)The Embarrassed Cryptographer(大数取模)

    The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13041 Accep ...

  6. 【大数取模】HDOJ-1134、CODEUP-1086

    1086: 大数取模   题目描述 现给你两个正整数A和B,请你计算A mod B.为了使问题简单,保证B小于100000. 输入 输入包含多组测试数据.每行输入包含两个正整数A和B.A的长度不超过1 ...

  7. HDU4704Sum 费马小定理+大数取模

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4704 题目大意: 看似复杂,其实就是求整数n的划分数,4=1+1+2和4=1+2+1是不同的.因而可 ...

  8. HDU--1212大数取模

    大数取模问题.题目传送门:HDU1212 #include <iostream> using namespace std; char a[1010]; int main() { int b ...

  9. HPU 1471:又是斐波那契数列??(大数取模)

    1471: 又是斐波那契数列?? 时间限制: 1 Sec 内存限制: 128 MB 提交: 278 解决: 27 统计 题目描述 大家都知道斐波那契数列吧?斐波那契数列的定义是这样的: f0 = 0; ...

随机推荐

  1. linux中的线程局部存储(TLS)

    http://blog.csdn.net/cywosp/article/details/26469435

  2. CxImage的编译及简单使用举例

    1.  从http://sourceforge.net/projects/cximage/下载最新的CxImage 702源代码. 2.  解压缩后,以管理员身份打开CxImageFull_vc10. ...

  3. android 浮动窗体学习笔记及个人理解(仿360手机助手)

    很感谢原文作者 http://blog.csdn.net/guolin_blog/article/details/8689140 经自己理解 程序执行界面例如以下图: 1.程序入口界面 2.小浮动窗体 ...

  4. [Spring实战系列](19)Servlet不同版本号之间的差别

    1.   2.3版本号 2.3版本号 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application ...

  5. Visual Studio Code 常用插件

    这里记录在Visual Studio Code中,我经常用到的插件. C#这个就不必说了,想用VIsual Studio Code调试和编辑C#代码,必须要装这个插件.东西还好,就是每次安装和更新插件 ...

  6. [读书笔记]流畅的Python(Fluent Python)

    <流畅的Python>这本书是图灵科技翻译出版的一本书,作者Luciano Ramalho. 作者从Python的特性角度出发,以Python的数据模型和特殊方法为主线,主要介绍了pyth ...

  7. Part1-Redefining your data-access strategy 重新定义你的数据访问策略

    欢迎来到Entity Framework 4 In Action,EF是微软3.5 SP1推出的ORM工具,现在已经更新到4.0版本(...)本书能确保你in a  robust and model- ...

  8. Django值聚合,分组,事物,cookie,session

    1,聚合(aggregate):是queryset的一个 终止语句,它返回一个包含键值对的字典,键是的名称是聚合值的标识符,值是计算出来的聚合值,键的名称是按照字段和聚合函数自动生成出来的.用到的内置 ...

  9. HTML5你必须知道的28个新特性

    1. 新的Doctype 尽管使用<!DOCTYPE html>,即使浏览器不懂这句话也会按照标准模式去渲染 2. Figure元素 用<figure>和<figcapt ...

  10. JSON with Java

    work with json-lib.jar import net.sf.json.JSONArray;import net.sf.json.JSONException;import net.sf.j ...