首页 > 专题系列 > Java解POJ > POJ 2305 Basic remains [解题报告] Java
2013
11-11

POJ 2305 Basic remains [解题报告] Java

Basic remains

问题描述 :

Given a base b and two 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 integer k such that p = a*m + k for some integer a.

输入:

Input consists of a number of cases. Each case is 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 1000 digits between 0 and b-1. The third, m, contains up to 9 digits between 0 and b-1. The last case is followed by a line containing 0.

输出:

For each test case, print a line giving p mod m as a base-b integer.

样例输入:

2 1100 101
10 123456789123456789123456789 1000
0

样例输出:

10
789

解题代码:

import java.io.BufferedInputStream;   
import java.math.BigInteger;   
import java.util.Scanner;   
public class Main {   
  
    public static void main(String[] args) {   
        Scanner scan = new Scanner(new BufferedInputStream(System.in));   
        while (scan.hasNext()) {   
            int b = scan.nextInt();   
            if (b == 0) {   
                break;   
            }   
            BigInteger p = scan.nextBigInteger(b);   
            BigInteger m = scan.nextBigInteger(b);   
            System.out.println(p.mod(m).toString(b));   
        }   
    }   
}

  1. Gucci New Fall Arrivals

    This is really nice to know. I hope it will be successful in the future. Good job on this and keep up the good work.

  2. 站长好。我是一个准备创业的互联网小白,我们打算做一个有关国*际*游*学的平台。手上也有了一些境外资源。现阶段的团队现在没有cto.原意出让一些管理股寻找一个靠谱的技术专家做合伙人, 不知道是不是能得到您的帮助。发个帖子或者其他方式。期待您的回应。可以加我微信tianxielemon聊聊。