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 ;
}

最新文章

  1. 终端指令操作创建Django项目
  2. iOS应用中的相关正则及验证
  3. Silicon Labs
  4. C#控件绑定数据源方式
  5. (转)Linux下安装Matlab2014及破解
  6. oc中的block
  7. TIANKENG’s rice shop
  8. POJ 3678 Katu Puzzle (2-SAT,常规)
  9. temporary
  10. Modifying the ASP.NET Request Queue Limit
  11. WinForm TextBox自定义扩展方法数据验证
  12. Advanced Fruits(HDU 1503 LCS变形)
  13. 面向对象的一小步:添加ActiveRecord的Scope功能
  14. Django---手动编写视图
  15. Netty官网首页(翻译)
  16. SFTP搭建@windows using freeSHHd&amp;FileZilla
  17. js动态添加和删除table的行例子
  18. 如何使用Python操纵Postgres数据库
  19. javascript的基础知识整理
  20. 13.8.8 div块 居中

热门文章

  1. strstr-strcat实现
  2. SQL 约束(Constraints)
  3. 有两个字符串a,b。假设a=&quot;ab&quot;,b=&quot;cd&quot;,判断字符串c=&quot;acbd&quot;是属于a、b的组合。满足组合后a、b的内部顺序均不变。
  4. 使用 maskView 设计动画
  5. HDU 5285 wyh2000 and pupil(dfs或种类并查集)
  6. 微博试水卖车社交电商怎样令4S“颤抖”?
  7. centos7 rpm 安装MySQL5.6
  8. web 开发之js---ajax 异步处理
  9. C项目实践--图书管理系统(2)
  10. Spring Security调研记录【七】--核心模型与实现