Big Number

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

Total Submission(s): 9006    Accepted Submission(s): 6100

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

(ABC)%n=(A*100%n+B*10%n+C%n)%n

(A*B)%n=(A%n*B%n)%n

于是,可以利用循环,对于挺大的数,利用字符串来表示这个数。

比如,令ABC为字符串,则有

1)sum=A%n;

2)A%n*10+B%n=sum+B%n

于是sum=(sum+B%n)%n

3)经过循环,会有:

sum=(sum+C%n)%n=((sum+B%n)%n*10+C%n)%n=((A%n*10+B%n)%n*10+C%n)%n=((A*100%n+B*10%n)%n+C%n)%n=(A*100%n+B*10%n+C%n)%n

故而可以用循环求解。

#include <iostream>
#include <string>
using namespace std;
int main()
{
string a;
int b,len,sum;
while(cin>>a>>b)
{
len=a.length();
sum=;
for(int i=;i<len;i++)
sum=(sum*+(a[i]-'')%b)%b;
cout<<sum<<endl;
}
return ;
}

用JAVA更简单

import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner (System.in);
int n;
BigInteger a,b;
while(in.hasNextBigInteger()) {
a=in.nextBigInteger();
b=in.nextBigInteger();
a=a.remainder(b);
System.out.println(a);
}
}
}

(大数取模)Big Number hdu1212的更多相关文章

  1. HDU--1212大数取模

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

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

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

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

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

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

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

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

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

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

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

  7. 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个东西中间插任意个板子 ...

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

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

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

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

  10. HDU-1226-超级密码-队列+广搜+大数取模

    Ignatius花了一个星期的时间终于找到了传说中的宝藏,宝藏被放在一个房间里,房间的门用密码锁起来了,在门旁边的墙上有一些关于密码的提示信息: 密码是一个C进制的数,并且只能由给定的M个数字构成,同 ...

随机推荐

  1. JS 字符串转换为number

    // '+ "42"' --> + 加上数字字符串可转换成数值 console.log(typeof (+ "42")); // 输出为 number

  2. git心得

    使用Git得到了以下体会: github在新的目录下添加新的文件 git init //在相应的目录下添加 git add //添加目录 git commit -m "first commi ...

  3. octave基本指令4

    octave基本指令4 图形化显示数据 >> t=[0:0.01:0.98]; >> y1 = sin(2*pi*4*t); %pi表示π >> plot(t,y1 ...

  4. JS平滑无缝滚动实现———实现首页广告自动滚动效果(附实例)

    本文我们实现纯JS方式的滚动广告效果. 先show一下成品: 首先是网页样式: 1. #demo { 2. background: #FFF; 3. overflow:hidden; 4. borde ...

  5. let申明与const申明

    ES6新增了let命令,用来声明变时量. 它的用法类似于var 但是所声明的变量,只在let命令所在的代码块内有效. // for(let i = 0; i<10 ;i++ ){ console ...

  6. msql 复杂练习

    https://blog.csdn.net/xiao__oaix/article/details/78122294 customer表branch 表account 表 depositor 表loan ...

  7. Python 2和Python 3的编码问题

    在Python2中,字符串无法完全地支持国际字符集和Unicode编码.为了解决这种限制,Python2对Unicode数据使用了单独的字符串类型.要输入Unicode字符串字面量,要在第一个引号前加 ...

  8. LinkedList 实现 Queue

    package cn.com.example; import java.util.LinkedList; /** * Created by Jack on 2017/3/8. */ public cl ...

  9. 可视化数据matplotlib之安装与简单折线图

    matplotlib是一个可视化数据的模块,安装前需要先安装Visual Studio Community:然后去https://pypi.python.org/pypi上查找matplotlib并下 ...

  10. Lodop打印条码二维码设置多宽不一定是多宽

    Lodop输出二维码和条码,可用如下语句,其中下面的width和height参数,设置了条码或二维码多宽,会发现可能不是设置的宽度或高度.ADD_PRINT_BARCODE(Top,Left,Widt ...