Enter a base B, and then input two big integers x and y based on the base B to calculate the base B result of X % Y.
Http: // 162.105.81.212/judgeonline/problem? Id = 2305
Function:
String ST = integer. tostring (Num, base); // convert num into base (base <= 35 ).
Int num = integer. parseint (St, base); // Use ST as the base and convert it to a 10-digit int (parseint has two parameters, and the first is the string to be converted, the second is to explain what the hexadecimal format is ).
Biginter M = new biginteger (St, base); // st is a string, and base is the base.
// Added by abilitytao
1. If you want to read a large number in binary format, you can use cin. nextbiginteger (2 );
Of course, you can also use other hexadecimal methods to read data;
2. If you want to convert a large number to a string in other hexadecimal forms, use cin. tostring (2); // convert it to a string in binary format.
import java.math.*; import java.util.*;import java.math.BigInteger;public class Main{ public static void main (String[] args)throws Exception { Scanner in=new Scanner(System.in); int b; BigInteger x,y; while(in.hasNextInt()) { b=in.nextInt(); if(b==0) break; x=in.nextBigInteger(b); y=in.nextBigInteger(b); x=x.mod(y); System.out.println(x.toString(b)); } } }