HDU1212:Big Number(大数求模)
2014-08-09 22:47
302 查看
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
#include<stdio.h>
#include<string.h>
int main()
{
char a[1000];
int b,len;
while(~scanf("%s%d",a,&b))
{
len=strlen(a);
int mod=0;
for(int i=0;i<len;i++)
{
mod*=10;
mod+=a[i]-'0';
mod=mod%b;
}
printf("%d\n",mod);
}
return 0;
}
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
#include<stdio.h>
#include<string.h>
int main()
{
char a[1000];
int b,len;
while(~scanf("%s%d",a,&b))
{
len=strlen(a);
int mod=0;
for(int i=0;i<len;i++)
{
mod*=10;
mod+=a[i]-'0';
mod=mod%b;
}
printf("%d\n",mod);
}
return 0;
}
相关文章推荐
- hdu1212 Big Number &第六届山东省赛Single Round Math (同余定理,大数取模)
- hdu1212 Big Number &第六届山东省赛Single Round Math (同余定理,大数取模)
- Big Number-大数运算
- 支持无限精度无限大数的类BigNumber实现
- hdoj1212(大数取余)Big Number
- 大数求模hdu1212
- 大数加法 big number add
- 求大数阶乘的位数(ACM Big Number问题)
- 大数big number的加减运算
- BigNumberPlus大数加法
- 要求实现方法public String addTwoBigNumber(String s1,string s2) 大数相加,注意处理异常
- HNOI2016 大数(number)
- java中biginteger和bigdecimal在大数计算中的使用
- Java高新技术——大数操作(BigInteger、BigDecimal)
- Big Number(求任意阶乘的位数)
- Java中的大数处理类BigInteger和BigDecimar浅析
- JAVA 大数(BigInteger) 归纳总结
- 数学_大数求模(HDU_1021)
- C++大数模板 BigInteger
- HDU 6093 Rikka with Number(java大数+思维)