POJ 2305 Basic Remains (Java practice)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.