当前位置: 代码迷 >> 综合 >> POJ 1894 Alternative Scale of Notation .
  详细解决方案

POJ 1894 Alternative Scale of Notation .

热度:52   发布时间:2023-09-23 04:22:04.0

题目地址:http://poj.org/problem?id=1894

import java.util.*;
import java.math.*;
import java.text.*;
import java.io.*;public class Main
{public static void main(String[] args) {Scanner cin = new Scanner(new BufferedInputStream(System.in));int base=cin.nextInt();BigInteger n=cin.nextBigInteger();String ans = new String();while(n.compareTo(BigInteger.ZERO)!=0){if(n.mod(BigInteger.valueOf(base)).compareTo(BigInteger.ZERO)==0){ans=base+ans;n=n.divide(BigInteger.valueOf(base)).subtract(BigInteger.ONE);}else {ans=n.mod(BigInteger.valueOf(base))+ans;n=n.divide(BigInteger.valueOf(base));}}System.out.println(ans);}
}



  相关解决方案