Big Number
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
Author
Ignatius.L
Source
Recommend
Eddy
在做题之前,先了解这样一些结论:
A*B % C = (A%C * B%C)%C
(A+B)%C = (A%C + B%C)%C
如 532 mod 7 =(500%7+30%7+2%7)%7;
当然还有a*b mod c=(a mod c+b mod c)mod c;
如35 mod 3=((5%3)*(7%3))%3
有了这一些结论,题目就好做了!
代码如下:
#include<iostream>
#include<string.h>
using namespace std;
const int MAX=100010;
int main()
{
char str[MAX];
int s,len,sum;
while(scanf("%s%d",str,&s)!=EOF)
{
len=strlen(str);
sum=0;
for(int i=0;i<len;i++)
sum=(sum*10+(str[i]-'0')%s)%s;
cout<<sum<<endl;
}
return 0;
}
分享到:
相关推荐
杭电oj1000题解题报告
杭电OJ题目分类的叙述,可以方便去学习去做。
杭电OJ 2028代码 the rosolve of the hdu 2028
杭电OJ(1000-1099) AC 代码
本资源主要提供了杭电oj题目分类和自测状况两大类 可实现随机选题等功能.
杭电OJ部分威士忌的代码 杭电OJ部分威士忌的代码杭电OJ部分威士忌的代码
杭电oj上的一些疑问,适用于初学者,可以解答一些疑问 都是一些水题
杭电oj 1047习题
杭电oj分类
杭州电子科技大学 oj离线版
这是HDUOJ上面的140道题目的答案,其中大部分都是简单题,有些太简单的就没有收集进去,代码为C/C++,全都AC了的,其中有些有具体的说明是怎么做的,例如博弈论那些
课程资源 杭电OJ1000-1099答案 ,仅供参考...
杭电oj的离线版以及题目分类的文档 更加一目了然 方便选择适合的题目做 适合暂时上不了网的用于练习
这是杭电OJ上某些题的解题报告,后续还有上传很多!
基于Laravel 5.0的OJ题解网站 , 目前涵盖安科OJ,南阳OJ,杭电OJ ,北大OJ,浙大OJ.zip
杭电oj1048答案,c++代码,适合初学者,思路简单
这是杭电oj入门100题的题号,通过这100题可以掌握基本输入输出操作,及基本算法
杭电ACM2000-2011题已提交的代码!保证正确!