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
2
5
1521

提炼:数字转化为字符串处理,每位取模。

#include<stdio.h>
#include<string.h>
int main(void){
char number[1001];
int b,ans;
while(scanf("%s %d",number,&b)!=EOF){
int len=strlen(number);
ans=0;
for(int i=0;i<len;i++){
ans=(ans*10+(number[i]-'0'))%b;
}
printf("%d\n",ans);
}
return 0;
}

题目来源:

http://acm.hdu.edu.cn/showproblem.php?pid=1212

简单&&大数取模的更多相关文章

  1. 【大数取模】HDOJ-1134、CODEUP-1086

    1086: 大数取模   题目描述 现给你两个正整数A和B,请你计算A mod B.为了使问题简单,保证B小于100000. 输入 输入包含多组测试数据.每行输入包含两个正整数A和B.A的长度不超过1 ...

  2. hdu2302(枚举,大数取模)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2303 题意:给出两个数k, l(4<= k <= 1e100, 2<=l<=1 ...

  3. (POJ2635)The Embarrassed Cryptographer(大数取模)

    The Embarrassed Cryptographer Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13041 Accep ...

  4. HDU4704Sum 费马小定理+大数取模

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4704 题目大意: 看似复杂,其实就是求整数n的划分数,4=1+1+2和4=1+2+1是不同的.因而可 ...

  5. HDU--1212大数取模

    大数取模问题.题目传送门:HDU1212 #include <iostream> using namespace std; char a[1010]; int main() { int b ...

  6. ACM-ICPC 2018 焦作赛区网络预赛G Give Candies(隔板定理 + 小费马定理 + 大数取模,组合数求和)题解

    题意:给你n个东西,叫你把n分成任意段,这样的分法有几种(例如3:1 1 1,1 2,2 1,3 :所以3共有4种),n最多有1e5位,答案取模p = 1e9+7 思路:就是往n个东西中间插任意个板子 ...

  7. HPU 1471:又是斐波那契数列??(大数取模)

    1471: 又是斐波那契数列?? 时间限制: 1 Sec 内存限制: 128 MB 提交: 278 解决: 27 统计 题目描述 大家都知道斐波那契数列吧?斐波那契数列的定义是这样的: f0 = 0; ...

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

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

  9. HDU-2303 The Embarrassed Cryptographer 高精度算法(大数取模)

    题目链接:https://cn.vjudge.net/problem/HDU-2303 题意 给一个大数K,和一个整数L,其中K是两个素数的乘积 问K的是否存在小于L的素数因子 思路 枚举素数,大数取 ...

随机推荐

  1. UVA 11475 Extend to Palindrome (kmp || manacher || 后缀数组)

    题目链接:点击打开链接 题意:给你一个串,让你在串后面添加尽可能少的字符使得这个串变成回文串. 思路:这题可以kmp,manacher,后缀数组三种方法都可以做,kmp和manacher效率较高,时间 ...

  2. A. Vitaly and Strings

    Vitaly is a diligent student who never missed a lesson in his five years of studying in the universi ...

  3. 【2020杭电多校】Distinct Sub-palindromes 找规律

    题目链接:Distinct Sub-palindromes 题意: 给你一个长度n,你需要找出来一些串,这些串由A...Z和a...z构成.我们设长度为n的所有串中所包含回文子串最少的数量为ans.问 ...

  4. 2019-2020 ACM-ICPC Brazil Subregional Programming Contest Problem M Maratona Brasileira de Popcorn (二分)

    题意:有\(n\)袋爆米花,某个队伍有\(c\)个队员,每个队员每秒做多可以吃\(t\)粒爆米花,但一袋爆米花只能由一个队员吃完,并且一个队员只能吃连续的一袋或几袋,不能隔着吃某一袋,求将所有爆米花吃 ...

  5. C - C工程编译那些事【configure-make || cmake-make】

    一.cofigure是怎么生成的,我们又是怎么使用的 configure和make install背后的故事: https://azyet.github.io/2015/06/20/configure ...

  6. Linux下的C语言编程

    一.在Linux下的C语言编程所需工具(下面所列举的都是我编程所用的工具) 1.文本编辑器 Vim 2.编译链接工具 gcc 3.调试器 gdb 4.项目管理工具 make和makefile 二.VI ...

  7. Cron表达式在 定时执行专家 5.0 中的使用方式

    在<定时执行专家 V5.0>程序内部使用了包含 6 位的 Cron表达式,第一个字段(second)没有使用.程序内部一直 second 位是 0.在 Cron表达式的界面上可以设置 5位 ...

  8. 逆元 exgcd 费马小定理 中国剩余定理的理解和证明

    一.除法取模逆元 如果我们要通过一个前面取过模的式子递推出其他要取模的式子,而递推式里又存在除法 那么一个很尴尬的事情出现了,假如a[i-1]=100%31=7 a[i]=(a[i-1]/2)%31 ...

  9. 进程控制——fork-and-exec、system、wait

    forc-and-exec流程 父进程与子进程之间的关系十分复杂,最大的复杂点在于进程间相互调用.Linux下这一流程称为fork-and-exec.父进程通过fork的方式产生一个一模一样的子进程, ...

  10. apt 和 apt-get 之间有什么区别?

    使用ubuntu的朋友一定会接触一个命令就是apt-get . 使用该工具安装各种应用程序那叫一个爽. 在 Ubuntu 16.04 发行后,apt使用渐渐频繁起来. 那么,apt-get 与 apt ...