Persistent Numbers(大数+发现java注意点!!!)
来源:互联网 发布:淘宝官方微博有哪些 编辑:程序博客网 时间:2024/06/07 04:50
Link:点击打开链接
Problem:
Description
679 -> 378 -> 168 -> 48 -> 32 -> 6.
That is, the persistence of 679 is 6. The persistence of a single digit number is 0. At the time of this writing it is known that there are numbers with the persistence of 11. It is not known whether there are numbers with the persistence of 12 but it is known that if they exists then the smallest of them would have more than 3000 digits.
The problem that you are to solve here is: what is the smallest number such that the first step of computing its persistence results in the given number?
Input
Output
Sample Input
0147184951768-1
Sample Output
101114172977There is no such number.2688
Source
错误代码:
import java.util.*;
import java.io.*;import java.math.*;
import java.text.*;
public class Main{
public static void main(String[] args)
{
BigInteger x;
int i;
String s;
Scanner cin=new Scanner(System.in);
while(cin.hasNext())
{
x=cin.nextBigInteger();
if(x.compareTo(BigInteger.valueOf(-1))==0)
break;
if(x.compareTo(BigInteger.valueOf(10))<0)
{
System.out.println("1"+x);
}
else
{
s="";
for(i=9;i>=2;i--)
{
while(x.mod(BigInteger.valueOf(i))==BigInteger.valueOf(0))//这样写poj是wa!!!
{
s=i+s;
x=x.divide(BigInteger.valueOf(i));
}
}
if(x.compareTo(BigInteger.ONE)!=0)
{
System.out.println("There is no such number.");
}
else
{
System.out.println(s);
}
}
}
}
}
发现后改正AC代码:
import java.util.*;
import java.io.*;
import java.math.*;
import java.text.*;
public class Main{
public static void main(String[] args)
{
BigInteger x;
int i;
String s;
Scanner cin=new Scanner(System.in);
while(cin.hasNext())
{
x=cin.nextBigInteger();
if(x.compareTo(BigInteger.valueOf(-1))==0)
break;
if(x.compareTo(BigInteger.valueOf(10))<0)
{
System.out.println("1"+x);
}
else
{
s="";
for(i=9;i>=2;i--)
{
while(x.mod(BigInteger.valueOf(i)).compareTo(BigInteger.valueOf(0))==0)//就改了这一句就AC了!!!
{
s=i+s;
x=x.divide(BigInteger.valueOf(i));
}
}
if(x.compareTo(BigInteger.ONE)!=0)
{
System.out.println("There is no such number.");
}
else
{
System.out.println(s);
}
}
}
}
}
- Persistent Numbers(大数+发现java注意点!!!)
- POJ2325 Persistent Numbers(大数+贪心)
- Persistent Numbers(贪心+高精度)
- Persistent Numbers
- TOJ 2424 POJ 2325 ZOJ 1923 Persistent Numbers /贪心 + 大数除法
- POJ 2325 Persistent Numbers
- poj 2325 Persistent Numbers
- poj 2325 Persistent Numbers
- UVa10527 - Persistent Numbers(数论)
- poj 2325 Persistent Numbers
- POJ 2325 Persistent Numbers .
- poj 2325 Persistent Numbers(高精度除法+贪心)
- UVA-10579 Fibonacci Numbers(Java大数)
- Java混淆点、注意点
- POJ 2325 Persistent Numbers 笔记
- java基础注意点
- Java注意点
- java调试注意点
- 注册一个新账号,从今天开始写博客
- 写一些链表中头和尾节点/指针的常规用法
- IP地址分类
- git delete remote branches
- nyoj60谁获得了最高奖学金
- Persistent Numbers(大数+发现java注意点!!!)
- android 导包 导入jar包,打包jar包,打包成library。 KanKanStyle
- rman restore:在备份中恢复丢失的文件
- NSIS隐藏窗口标题栏自带的按钮(最大化,最小化,关闭X)
- UML类关系:依赖,关联,聚合和组合
- 迭代加深搜索——PQJ2286
- 数构线性链表ADT
- ygfmobileORACLE中用rownum分页并排序的SQL语句
- UVA10765-Doves and bombs(BCC)