POJ 2305 Basic remains

http://poj.org/problem?id=2305

大数的进制转化

题意:以b进制输入p和m,求p模m的b进制结果


import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static public void main(String[] args) throws IOException
    {
        Scanner cin =new Scanner(System.in);
        String result;
        int b;
        BigInteger p, m, res;
        while (cin.hasNext())
        {
        	b = cin.nextInt();
        	if (b == 0)
        		break;
        	p = cin.nextBigInteger(b);    //以b进制输入p
        	m = cin.nextBigInteger(b);    //以b进制输入m
        	res = p.mod(m);               //得到p模m的十进制结果
        	result = res.toString(b);     //转为b进制到字符串result中
        	System.out.println(result);
        }
    }
}

你可能感兴趣的:(java,ACM)