题解报告:hdu 1212 Big Number(大数取模+同余定理)
2024-09-03 07:55:51
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.
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 ;
}
最新文章
- 终端指令操作创建Django项目
- iOS应用中的相关正则及验证
- Silicon Labs
- C#控件绑定数据源方式
- (转)Linux下安装Matlab2014及破解
- oc中的block
- TIANKENG’s rice shop
- POJ 3678 Katu Puzzle (2-SAT,常规)
- temporary
- Modifying the ASP.NET Request Queue Limit
- WinForm TextBox自定义扩展方法数据验证
- Advanced Fruits(HDU 1503 LCS变形)
- 面向对象的一小步:添加ActiveRecord的Scope功能
- Django---手动编写视图
- Netty官网首页(翻译)
- SFTP搭建@windows using freeSHHd&;FileZilla
- js动态添加和删除table的行例子
- 如何使用Python操纵Postgres数据库
- javascript的基础知识整理
- 13.8.8 div块 居中
热门文章
- strstr-strcat实现
- SQL 约束(Constraints)
- 有两个字符串a,b。假设a=";ab";,b=";cd";,判断字符串c=";acbd";是属于a、b的组合。满足组合后a、b的内部顺序均不变。
- 使用 maskView 设计动画
- HDU 5285 wyh2000 and pupil(dfs或种类并查集)
- 微博试水卖车社交电商怎样令4S“颤抖”?
- centos7 rpm 安装MySQL5.6
- web 开发之js---ajax 异步处理
- C项目实践--图书管理系统(2)
- Spring Security调研记录【七】--核心模型与实现