import java.math.*;
import java.util.*;
public class Main
{
public static void main(String []args)
{
Scanner cin = new Scanner(System.in);
BigInteger zero = new BigInteger(String.valueOf(0));
BigInteger one = new BigInteger(String.valueOf(1));
BigInteger _one = new BigInteger(String.valueOf(-1));
BigInteger nine = new BigInteger(String.valueOf(9));
while(cin.hasNext())
{
BigInteger n = cin.nextBigInteger();
if(n.equals(_one)) break;
int num = 0;
int ans[] = new int[10000];
int k = 0;
if(n.equals(zero))
{
ans[0] = 0;
ans[1] = 1;
k = 2;
}
else if(n.equals(one))
{
ans[0] = 1;
ans[1] = 1;
k = 2;
}
else
for(int i = 9;i > 0;i --)
{
BigInteger m = new BigInteger(String.valueOf(i));
//System.out.print(m.toString());
while(n.mod(m).equals(zero))
{
n = n.divide(m);
if(n.equals(one))
{
if(num >= 1)
{
if(k > 1)
break;
else
{
ans[k ++]= i;
num ++;
}
}
else
{
ans[k ++] = i;
num ++;
}
}
else
{
if(i == 1 && n.compareTo(nine) == 1 )
{
k = 0;
break;
}
else
{
ans[k ++] = i;
}
}
}
}
//System.out.print(k);
if(k == 0)
System.out.print("There is no such number.");
else
for(int i = k-1;i >= 0;i --)
{
System.out.print(ans[i]);
}
System.out.println();
}
}
}
POJ 2325
最新推荐文章于 2020-08-17 22:30:28 发布