Big Number(大数)

Big Number

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5857    Accepted Submission(s):
4093
点我

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

 1 #include <iostream>
 2 #include <cstring>
 3 using namespace std;
 4 int main()
 5 {
 6     int n,i,j;
 7     char a[1002];
 8     while(cin>>a>>n)
 9     {
10         int count=0,c=0,m=0;
11         count=strlen(a)-1;
12         for(i=0;i<=count;i++)
13         {
14             m=a[i]-‘0‘+c*10;
15             c=m%n;
16         }
17         cout<<c<<endl;
18         memset(a,0,sizeof(a));
19     }
20 }
时间: 2024-11-10 19:55:20

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

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

SGU 407 Number of Paths in the Empire dp+java大数

SGU 407 407. Number of Paths in the Empire Time limit per test: 0.75 second(s) Memory limit: 65536 kilobytes input: standard output: standard During the period of Tsam dynasty ruling people rarely fought against each other and their neighbours, becau

hdu1212 Big Number &amp;第六届山东省赛Single Round Math (同余定理,大数取模)

题目链接:Big Number 题目大意:每次输入两个数,第一个是高精度,第二个数小于100000:求 a mod b 根据同余定理: (a+b)% c = (a%c+ b%c)%c (a*b)%c =  ( a%c* b%c)%c 所以 对于大数,例如 :123 可以这样分解 123 =  (1*10+2)*10 + 3: 123 % c =   (  (  (  1%c *  10%c)%c + 2%c) %c  * 10%c) + 3 %c  ) %c; 因此,我们用字符串处理这个数,通过

PAT 甲级 1024 Palindromic Number (25 分)(大数加法,考虑这个数一开始是不是回文串)

1024 Palindromic Number (25 分) A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers. Non-palindromic n

K-th Number(第k大数)

K-th Number Time Limit: 20000MS   Memory Limit: 65536K Total Submissions: 45710   Accepted: 15199 Case Time Limit: 2000MS Description You are working for Macrohard company in data structures department. After failing your previous task about key inse

POJ 2104 K-th Number(区间第k大数)(平方分割,归并树,划分树)

题目链接: http://poj.org/problem?id=2104 解题思路: 因为查询的个数m很大,朴素的求法无法在规定时间内求解.因此应该选用合理的方式维护数据来做到高效地查询. 如果x是第k个数,那么一定有 (1)在区间中不超过x的数不少于k个 (2)在区间中小于x的数有不到k个 因此,如果可以快速求出区间里不超过x的数的个数,就可以通过对x进行二分搜索来求出第k个数是多少. 接下来,我们来看一下如何计算在某个区间里不超过x个数的个数.如果不进行预处理,那么就只能遍历一遍所有元素.