杭电1212 Big Number
来源:互联网 发布:淘宝入门教程 编辑:程序博客网 时间:2024/04/28 20:20
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 312 7152455856554521 3250
Sample Output
251521
//首先你应该了解
模运算的基本性质
运算规则
模运算与基本四则运算有些相似,但是除法例外。其规则如下:
(a + b) % p = (a % p + b % p) % p (1) //用到了这个
(a - b) % p = (a % p - b % p) % p (2)
(a * b) % p = (a % p * b % p) % p (3)
ab % p = ((a % p)b) % p (4)
结合率:
((a+b) % p + c) % p = (a + (b+c) % p) % p (5)
((a*b) % p * c)% p = (a * (b*c) % p) % p (6)
交换率: (a + b) % p = (b+a) % p (7)
(a * b) % p = (b * a) % p (8)
分配率: ((a +b)% p * c) % p = ((a * c) % p + (b * c) % p) % p (9)
重要定理
若a≡b (% p),则对于任意的c,都有(a + c) ≡ (b + c) (%p);(10)
若a≡b (% p),则对于任意的c,都有(a * c) ≡ (b * c) (%p);(11)
若a≡b (% p),c≡d (% p),则 (a + c) ≡ (b + d) (%p),(a - c) ≡ (b - d) (%p), (a * c) ≡ (b * d) (%p),(a / c) ≡ (b / d) (%p); (12)
若a≡b (% p),则对于任意的c,都有ac≡ bc (%p); (13)
#include<stdio.h>#include<string.h>#define max 11000int main(){int i,n,len;char str[max];while(~scanf("%s %d",str,&n)){len=strlen(str);int res=0;for(i=0;i<len;++i){res=(res*10+(str[i]-'0')%n)%n;//其实可以类比除法运算}printf("%d\n",res);}return 0;}
0 0
- 杭电 1212 Big Number
- 杭电1212 Big Number
- 杭电1212Big Number
- 【杭电】[1212]Big Number
- 杭电 Big Number
- 杭电 HDU ACM 1212 Big Number
- 杭电1018 Big Number
- 杭电1018 Big Number
- 杭电 1018 Big Number
- 杭电1018-Big Number
- 杭电 1018 Big Number
- 杭电 1018 Big Number
- 杭电1018 Big number
- 杭电1018 Big Number
- 杭电1018Big Number
- 杭电1018Big Number
- 杭电1018 BIG NUMBER
- 杭电OJ1212-Big Number
- 深入学习请求响应(二)---response实现验证码
- 一些有用的东西
- 欧拉函数
- 关于正则表达式的基础详解
- mysql数据库备份(sqlbak.bat)文件
- 杭电1212 Big Number
- mongodb使用-增删改查、colleciton关联、_id作为主键实现update
- 电感式dcdc原理(转)
- 黑马程序员——第七篇_高新技术
- 关于JSP的九大内置对象
- 从一个“变态”的题看“分析Java源代码”的重要性!
- 了解NoSQL
- 利用standford-nlp库实现Naive Bayes文本分类系统
- App11