同余定理之杭电1212_Big Number
2016-07-24 11:48
295 查看
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, you have to ouput the result of A mod B.
[align=left]Sample Input[/align]
2 3
12 7
152455856554521 3250
[align=left]Sample Output[/align]
2
5
1521
AC代码如下:
#include "iostream"
using namespace std;
int main(int argc, char* argv[])
{
char a[1001];
int i,b,s,sum;
while(cin>>a>>b)
{
s=strlen(a);
sum=0;
for (i=0;i<s;i++)
{
sum=(sum*10+a[i]-48)%b;
}
cout<<sum<<endl;
}
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
For each test case, you have to ouput the result of A mod B.
[align=left]Sample Input[/align]
2 3
12 7
152455856554521 3250
[align=left]Sample Output[/align]
2
5
1521
AC代码如下:
#include "iostream"
using namespace std;
int main(int argc, char* argv[])
{
char a[1001];
int i,b,s,sum;
while(cin>>a>>b)
{
s=strlen(a);
sum=0;
for (i=0;i<s;i++)
{
sum=(sum*10+a[i]-48)%b;
}
cout<<sum<<endl;
}
return 0;
}
相关文章推荐
- POJ 1861 Network .
- linux date命令
- 杨辉三角&二项式定理
- python day six
- java中数组的相关知识小结(推荐)
- 基于VanlOS 10 CMP Red Whale 持续集成实践
- Codeforces Dima and Guards
- CISCO 基础
- js
- 指针的指针
- (转)IC验证概述
- chapter 1 let 和 const
- JS中数组的常见用法
- Pycharm 2016激活码
- Tableau 如何计算增长(去年及上个月或之前月份的)值
- 144. Binary Tree Preorder Traversal
- SDUT 2141 数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历
- JSP技术(二)——JSP指令
- PAT 1016 Mice and Rice (25)
- 超级表格创始人中学时代揭秘