ACM--大数取模--HDOJ 1212--Big Number--水

HDOJ题目地址:传送门

Big Number

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

Total Submission(s): 7350    Accepted Submission(s): 5079

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
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
	    Scanner cin= new Scanner(System.in);
	    while(cin.hasNext()){
	    	BigInteger a=cin.nextBigInteger();
	    	BigInteger b=cin.nextBigInteger();
	    	BigInteger c= a.mod(b);
	    	System.out.println(c.toString());
	    }
   }
}
时间: 2024-11-09 01:42:52

ACM--大数取模--HDOJ 1212--Big Number--水的相关文章

大数取模

//大数取模 #include "cmath" #include "iostream" #include "string.h" using namespace std; int mod(char str[],int num) { int number[100]; for(int i=0;i<strlen(str);i++) number[i]=str[i]-'0'; int remainder=0; for(int i=0;i<str

hdu2302(枚举,大数取模)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2303 题意:给出两个数k, l(4<= k <= 1e100, 2<=l<=1e6):其中k是两个素数的乘积,问k是否存在严格小于l的因子,若有,输出 BAD 该因子,反之输出GOOD: 思路: 先1e6内素数打表,再枚举一个因子,判断因子用大数取模: 代码: 1 #include <iostream> 2 #include <stdio.h> 3 #inclu

快速幂+大数取模

快速幂+大数取模 快速幂,其实就是求(a^b)% p,(其中a,b,p都比较大在int范围内)这类问题. 首先要知道取余的公式:(a*b)%p=(a%p*b%p)%p. 那么幂不就是乘机的累积吗,由此给出代码: int fast(int a,int b,int p) {   long long a1=a,t=1; while(b>0) { if(b&1)          /如果幂b是奇数多乘一次,因为后边会除2变偶数,(7/2=3) t=(t%p)*(a1%p)%p; a1=(a1%p)*

csu 1556: Jerry&#39;s trouble(大数取模)

题意:求出1^m+2^m+...n^m 思路:直接套用模板 #include<cstdio> #include<iostream> #include<cstring> #include<cmath> #include<stdlib.h> #include<algorithm> #include<queue> #include<stack> #include<ctype.h> #define LL l

POJ 1426 Find The Multiple(大数取模)【DFS】||【BFS】

<题目链接> 题目大意: 给一个小于200的正整数n,问只有0和1组成的位数小于100的最小能被n整除的数是多少. 解题分析: 用DFS或者BFS沿着位数进行搜索,每一次搜索到下一位都有两种情况,0或者1,还要注意的是,大数取模的方法.但是我有一个疑问,这题位数最高为100,用dfs为什么不会超时?还是说只是此题数据太弱吗? BFS解法 #include<iostream> #include<cstdio> #include<queue> #include&

HDU 1212 Big Number(C++ 大数取模)(java 大数类运用)

Big Number 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 --每天在线,欢迎留言谈论. 题目大意: 给你两个数 n1,n2.其中n1 很大很大,n1%n2的值. 知识点: ①秦九韶公式:例:1314= ((1*10+3)*10+1)*10+4 ②(a*b)%c == (a%c)*(b%c) .(a+b)%c == (a%c)+(b%c) . 思路: 每步取模即可. C++ AC代码: 1 #include <iostream>

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

poj2635--The Embarrassed Cryptographer(数论篇1,大数取模)

The Embarrassed Cryptographer Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 12496   Accepted: 3330 Description The young and very promising cryptographer Odd Even has implemented the security module of a large system with thousands of

机试真题 大数取模运算

之前总结过,大数问题,取模就是取商取余数: #include<iostream> #include<stdlib.h> #include<string> using namespace std; string devide(int& r, string s, int n) { string ss = ""; for (int i = 0; i < s.size(); i++) { int temp = r*10 + int(s[i] -

UVA128 - Software CRC(大数取模)

题目链接 题目大意:给你一个字符串,这个字符串代表的是256进制的一个数,要求在这个字符串后面再加上两个两个字节,使得这个新的字符串的值取模于34943等于0.最后要求你输出这两个字节(十六进制). 解题思路:256进制的数先转化成十进制的数m,然后求出还需要的数n使得(n + m)%34943 ==0 ,最后再将n转换成16进制的数输出就可以了. 代码: #include <cstdio> #include <cstring> typedef long long ll; cons