当前位置: 代码迷 >> 综合 >> POJ 2325 Persistent Numbers .
  详细解决方案

POJ 2325 Persistent Numbers .

热度:124   发布时间:2023-09-23 04:18:46.0

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

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));while(cin.hasNext()){BigInteger x=cin.nextBigInteger();if(x.equals(BigInteger.valueOf(-1))) break;String ans=new String();if(x.equals(BigInteger.ZERO)) ans="10";if(x.equals(BigInteger.ONE)) ans="11";boolean done=true;while(x.compareTo(BigInteger.ONE)>0){boolean ok=false;for(int i=9;i>=2;i--) if((x.mod(BigInteger.valueOf(i))).equals(BigInteger.ZERO)) {ans=i+ans;x=x.divide(BigInteger.valueOf(i));ok=true;break;}if(ok==false) {done=false;break;}}if(!done) System.out.println("There is no such number.");else {if(ans.length()==1) ans='1'+ans;System.out.println(ans);}}}
}