BigInteger的构造函数BigInteger(string, base)可以用来进行进制转换,把base进制转为10进制。
输出时BigInteger.toString(base)是把10进制数按base进制输出。
View Code
import java.io. * ; import java.util. * ; import java.math. * ; public class Main { public static void main(String args[]) { Scanner cin = new Scanner( new BufferedInputStream(System.in)); while ( true ) { int b = cin.nextInt(); if (b == 0 ) break ; String y = cin.next(); String z = cin.next(); BigInteger p = new BigInteger(y, b); BigInteger m = new BigInteger(z, b); BigInteger ans = p.mod(m); System.out.println(ans.toString(b)); } }}