Description
Given a base B and 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 an integer k such that p = a*m + K for some integer a.
Input
Input consists of a number of cases. Each case was 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 digits between 0 and b-1. The third, M, contains up to 9 digits between 0 and b-1. The last case was followed by a line containing 0.
Output
For each test case, the print a line giving P mod m as a base-b integer.
Sample Input
2 1100 10110) 123456789123456789123456789 10000
Sample Output
10789
The p%m is a B-binary representation. Decisive java.
Import java.io.*;import java.math.*;import java.util.*;p ublic 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);}}}
POJ 2305 Basic Remains (Java practice)