这道题目很有趣的,建议学编程的人都自己动手编编,编不出来去百度查查,然后贴出自己的答案
if((i==1||(i%2==0)||(i%3==0)||(i%5==0))&&(i%7!=0)&&(i%11!=0))
这样对么?
2010-06-26 15:14
2010-06-26 22:23
2010-06-26 22:50
2010-06-26 23:05
2010-06-27 11:26
2010-06-27 12:05
程序代码:
public class Perm {
int count =0;
int n=1;
public void getAll(){
while(true){
int i=n;
while(i%5==0){
i=i/5;
}
while(i%3==0){
i=i/3;
}
while(i%2==0){
i=i/2;
}
if(i==1&&n!=1)
count++;
if(count==1500)
break;
n++;
}
}
public static void main(String[] args) {
Perm p = new Perm();
p.getAll();
System.out.println(p.n);
}
}
程序代码:public class Perm {
private int a2=0,a3=0,a5=0;
private int[] a = new int[1501];
private void getNth(int n){
a[0]=1;
for(int i=1;i<=n;i++){
int temp2 = 2*a[a2];
int temp3 = 3*a[a3];
int temp5 = 5*a[a5];
int temp = temp2<temp3?temp2:temp3;
temp=temp<temp5?temp:temp5;
a[i]=temp;
if(temp2==temp)
a2++;
if(temp3==temp)
a3++;
if(temp5==temp)
a5++;
}
}
public static void main(String[] args) {
Perm p = new Perm();
p.getNth(1500);
System.out.println(p.a[1500]);
}
}是不是这个题目有点难啊,还是大家太懒了呢。
2010-06-28 10:28
2010-07-02 10:27

2010-07-08 09:17
dsfs
2010-07-22 20:26