Big Number

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

Total Submission(s): 4594    Accepted Submission(s): 3175
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

用到同余定理:(a+b)%c=(a%c+b%c)%c=(a+b%c)%c;    附:(a*b)%c=(a%c*b%c)%c;

#include <stdio.h>
#define maxn 1002 char str[maxn]; int main()
{
int m, ans, i;
while(scanf("%s%d", str, &m) != EOF){
ans = 0;
for(i = 0; str[i]; ++i){
ans = (ans * 10 + (str[i] - '0') % m) %m;
}
printf("%d\n", ans);
}
return 0;
}

HDU1212 Big Number 【同余定理】的更多相关文章

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

    Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  2. 题解报告:hdu 1212 Big Number(大数取模+同余定理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 Problem Description As we know, Big Number is al ...

  3. [ACM] POJ 2635 The Embarrassed Cryptographer (同余定理,素数打表)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 11978   A ...

  4. POJ 1465 Multiple (BFS,同余定理)

    id=1465">http://poj.org/problem?id=1465 Multiple Time Limit: 1000MS   Memory Limit: 32768K T ...

  5. CodeForces 17D Notepad(同余定理)

    D. Notepad time limit per test 2 seconds memory limit per test 64 megabytes input standard input out ...

  6. LightOJ1214 Large Division 基础数论+同余定理

    Given two integers, a and b, you should check whether a is divisible by b or not. We know that an in ...

  7. POJ 2635 The Embarrassed Cryptographer (千进制,素数筛,同余定理)

    The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15767   A ...

  8. AtCoder Regular Contest 119 C - ARC Wrecker 2(同余定理+思维)

    Problem Statement There are NN buildings along the AtCoder Street, numbered 11 through NN from west ...

  9. Light oj 1214-Large Division (同余定理)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1214 题意很好懂,同余定理的运用,要是A数被B数整除,那么A%B等于0.而A很大,那我 ...

随机推荐

  1. MessasgePack:一个小巧高效的序列化方式

    MessagePack是一种高效二进制序列化格式.可以在多种语言中进行快速数据交换,比如JSON格式等.它比Json更加小巧,更加高效,可以用于一些结构化数据存储 ,非常适合适用于消息总线,Memor ...

  2. Tasker 模拟重复点击按钮

    http://stackoverflow.com.80bola.com/questions/21544271/android-tasker-app-advance-input-shell-comman ...

  3. HDU1518 Square 【剪枝】

    Square Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Su ...

  4. apple developer D-U-N-S® Number

    From:https://developer.apple.com/support/D-U-N-S/ The D-U-N-S Number is a unique nine-digit number t ...

  5. MVC动态添加文本框,后台使用FormCollection接收

    在"MVC批量添加,增加一条记录的同时添加N条集合属性所对应的个体"中,对于前台传来的多个TextBox值,在控制器方法中通过强类型来接收.使用FormCollection也可以接 ...

  6. mysql-connector-java升级到6.0以后启动tomcat报错

    mysql-connector-java升级到6.0以后启动tomcat报错 java.sql.SQLException: The server time zone value '�й���׼ʱ��' ...

  7. windowsmobile 开发环境

    Windows Mobile 6开发环境的配置过程 需要的文件列表:1.Visual Studio 2005 Professional及更高的版本(Visual Studio 2005 Express ...

  8. 使用 Reachability 获取网络状态

    Reachability source https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Int ...

  9. 服务信息块协议 SMB(Server Message Block protocol)

    SMB(Server Message Block)是协议名,它能被用于Web连接和客户端与服务器之间的信息沟通. SMB协议 SMB最初是IBM的贝瑞·费根鲍姆(Barry Feigenbaum)研制 ...

  10. 在JSP中应用JavaBean

    1. 解决中文乱码的JavaBean 在JSP页面中,处理中文字符经常会出现字符乱码的现象,特别是通过表单传递中文数据时容易产生.它的解决办法有很多,如将request的字符集指定为中文字符集,编写J ...