hdoj-1212-Big Number【大数取余&简单题】

Big Number

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 6015 Accepted Submission(s): 4205

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

Author

Ignatius.L

Source

杭电ACM省赛集训队选拔赛之热身赛

Recommend

Eddy | We have carefully selected several similar problems for you:
1215 1211 1210 1214 1695

#include<stdio.h>
#include<string.h>
int main(){
	int b;
	char a[1010];
	while(~scanf("%s%d",a,&b)){
		 int len=strlen(a),res=0;
		 for(int i=0;i<len;++i){
		 	res=res*10+a[i]-'0';
		 	if(res>=b)
		 	res=res%b;
		 }
	     printf("%d\n",res);
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-11-05 19:30:13

hdoj-1212-Big Number【大数取余&简单题】的相关文章

hdu 1212 Big Number(大数取模)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7083    Accepted Submission(s): 4884 Problem Description As we know, Big Number is

1214 - Large Division -- LightOj(大数取余)

http://lightoj.com/volume_showproblem.php?problem=1214 这就是一道简单的大数取余. 还想还用到了同余定理: 所谓的同余,顾名思义,就是许多的数被一个数d去除,有相同的余数.d数学上的称谓为模.如a=6,b=1,d=5,则我们说a和b是模d同余的.因为他们都有相同的余数1. //// 数学上的记法为: a≡ b(mod d) 可以看出当n<d的时候,所有的n都对d同商,比如时钟上的小时数,都小于12,所以小时数都是模12的同商. 对于同余有三种

LightOJ 1214 - Large Division (大数取余)

1214 - Large Division PDF (English) Statistics Forum Time Limit: 1 second(s) Memory Limit: 32 MB Given two integers, a and b, you should checkwhether a is divisible by b or not. We know that an integer ais divisible by an integer b if and only if the

sum 大数取余+快速幂

Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 3980    Accepted Submission(s): 1620 Problem Description Sample Input 2 Sample Output 2 Hint 1. For N = 2, S(1) = S(2) = 1. 2. The input fil

大数求余简单办法(水)

Prepared for New Acmer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7477    Accepted Submission(s): 2826 Problem Description 集训进行了将近2个礼拜,这段时间以恢复性训练为主,我一直在密切关注大家的训练情况,目前为止,对大家的表现相当满意,首先是绝大部分队员

如何运用同余定理求余数【hdoj 1212 Big Number【大数求余数】】

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5930    Accepted Submission(s): 4146 Problem Description As we know, Big Number is always troublesome. But it's really important in our

FZU 2108(dfs模拟,大数取余)

K Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice FZU 2108 Description Given one non-negative integer A and one positive integer B, it’s very easy for us to calculate A Mod B. Here A Mod B means the

HDU 5832 A water problem 大数取余

A water problem Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 650    Accepted Submission(s): 333 Problem Description Two planets named Haha and Xixi in the universe and they were created with

PHP大数(浮点数)取余

一般我们进行取余运算第一个想到的就是用百分号%,但当除数是个很大的数值,超出了int范围时,这样取余就不准确了. php大数(浮点数)取余函数 /** * php大数取余 * * @param int or float $bn 除数 * @param int $sn 被除数 * @return int 余数 */ //大数(浮点数)取余方法 function Kmod($bn, $sn) { return intval(fmod(floatval($bn), $sn)); } 测试代码: //大