POJ 2305 Basic remains(JAVA练习)

Description

Given a base b and two non-negative base b integers p and m, compute p mod m and print the result as a base b integer. p mod m is defined as the smallest non-negative integer k such that p = a*m + k for some integer a.

Input

Input consists of a number of cases. Each case is represented by a line containing three unsigned integers. The first, b, is a decimal number between 2 and 10. The second, p, contains up to 1000 digits between 0 and b-1. The third, m, contains up to 9 digits
between 0 and b-1. The last case is followed by a line containing 0.

Output

For each test case, print a line giving p mod m as a base-b integer.

Sample Input

2 1100 101
10 123456789123456789123456789 1000
0

Sample Output

10
789
求p%m的b进制表示。果断java。
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
	public static void main(String[] arges){
        Scanner cin = new Scanner (System.in);
		int b;
		BigInteger p,m,ans;
		while(cin.hasNext())
		{
			b=cin.nextInt();
			String str;
			if(b==0)  break;
			p=cin.nextBigInteger(b);
			m=cin.nextBigInteger(b);
			ans=p.mod(m);
			str=ans.toString(b);
			System.out.println(str);
		}
	}
}

时间: 2024-10-01 05:57:42

POJ 2305 Basic remains(JAVA练习)的相关文章

poj 2305 Basic remains java

import java.math.BigDecimal; import java.math.BigInteger; import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner cin= new Scanner(System.in); int b=0; while(cin.hasNextInt())

poj 2305 Basic remains 高精度取余

题意: 裸的高精度取余. 分析: http://blog.csdn.net/sepnine/article/details/44092055有poj 1220任意进制转换的代码,这题用到其中的一部分,可作对比. 代码: //poj 2305 //sep9 #include <iostream> using namespace std; int b,m; char s1[1024],s2[16],ans[16]; int p[1024]; int main() { while(scanf(&qu

Basic remains java入门题

Basic remains input:   b p m    读入p进制的p,m,   求p%m   ,以b进制输出 1 import java.util.*; 2 import java.math.*; 3 import java.io.*; 4 import java.text.*; 5 6 public class Main 7 { 8 public static void main(String[] args) 9 { 10 // 对于大量输入,下面方式可能会快一些. 11 Scann

Basic remains

Problem Description Given a base b and two non-negative base b integers p and m, compute p mod m and print the result as a base b integer. p mod m is defined as the smallest non-negative integer k such that p = a*m + k for some integer a. Input Input

POJ Exponentiation(大浮点数JAVA轻松解决)

题目链接:Clicke Here~ java解决大数就是爽阿!~ 以前大数模板敲啊敲的,敲了半天发现一交果断wrong.只从学会了java妈妈在不用担心我遇到大数了/ 这道题遇到的Java函数有: stripTrailingZeros()            去掉后缀0 toPlainString()               返回大数的非科学计数法 startsWith() startsWith()函数介绍及扩展: 描述 startsWith(),endsWith()的作用,用法,判断字符

POJ 1001 Exponentiation(JAVA,BigDecimal-&gt;String)

题目 计算实数a的n次方,具体输出格式看案例 import java.util.*; import java.math.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); BigDecimal a = BigDecimal.ONE; BigDecimal ans = BigDecimal.ONE; int n; while(in.hasNextBi

POJ 2935 Basic Wall Maze

http://poj.org/problem?id=2935 Basic Wall Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2794   Accepted: 1271   Special Judge Description In this problem you have to solve a very simple maze consisting of: a 6 by 6 grid of unit sq

POJ 1131 Octal Fractions (Java大数,八进制转十进制)

Octal Fractions Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6959   Accepted: 3825 Description Fractions in octal (base 8) notation can be expressed exactly in decimal notation. For example, 0.75 in octal is 0.953125 (7/8 + 5/64) in d

算法之路——POJ刷题(Java,持续更新中)

先拿一些水题来练手了 1.POJ1000 import java.util.Scanner; /** * Created by mxcsky on 2015/1/25. */ public class POJ1000 { public static void main(String[] args){ Scanner in = new Scanner(System.in); int a = in.nextInt(); int b = in.nextInt(); System.out.println