日期:2014-05-20 浏览次数:20795 次
import java.util.Arrays;
public class Oula_62_2 {
final int P=10000;
String[] arr=new String[P];
public static void main(String[] args) {
new Oula_62_2();
}
public Oula_62_2(){
for(int i=1;i<=P;i++){
char[] ch=(((long)i)*i*i+"").toCharArray();
Arrays.sort(ch);
arr[i-1]=new String(ch);
}
int n;
for(int i=0;i<P;i++){
n=1;
int len=arr[i].length();
for(int j=i+1;j<P&&len==arr[j].length();j++){
//System.out.println(arr[i].equals(arr[j]));
if(arr[i].equals(arr[j]))n++;
}
if(n==5){
System.out.println(((long)i+1)*(i+1)*(i+1));
break;
}
}
}
}
public void find2()
{
long[] arr = new long[P];
for (int i = 1; i <= P; i++)
{
char[] ch = (((long) i) * i * i + "").toCharArray();
Arrays.sort(ch);
int count=ch.length;
for(int j=0;j<count/2;j++)
{
char tmp=ch[j];
ch[j]=ch[count-1-j];
ch[count-1-j]=tmp;
}
arr[i - 1] = Long.parseLong(new String(ch));
}
int n;
for (int i = 0; i < P; i++)
{
n = 1;
for (int j = i + 1; j < P ; j++)
{
// System.out.println(arr[i].equals(arr[j]));
if (arr[i]==arr[j])
n++;
}
if (n == 5)
{
System.out.println(""+(i+1)+"^3="+((long) i + 1) * (i + 1) * (i + 1));
break;
}
}
}