求Humble Numbers

王朝java/jsp·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Humble Numbers

当一个数的因子只有2,3,5,7时,它被称为是Humble Numbers,例如1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27是前20个Humble Numbers。

求第100个(1分),第1000个(3分),和第5842个(4分)Humble Numbers

我的算法:

public class HNList {

public static void main(String[] args) throws Exception {

int[] hnList = new int[5842];

hnList[0] = 1;

int i2 = 0;

int i3 = 0;

int i5 = 0;

int i7 = 0;

for (int i=1;i < hnList.length;i++){

hnList[i] = getMinNumber(2*hnList[i2],3*hnList[i3],5*hnList[i5],7*hnList[i7]);

if (hnList[i]==2*hnList[i2]){

i2++;

}

if (hnList[i]==3*hnList[i3]){

i3++;

}

if (hnList[i]==5*hnList[i5]){

i5++;

}

if (hnList[i]==7*hnList[i7]){

i7++;

}

}

System.out.println(hnList[100-1]);

System.out.println(hnList[1000-1]);

System.out.println(hnList[5842-1]);

}

public static int getMinNumber(int i1,int i2,int i3,int i4){

int iRtn = 0;

iRtn = getMinNumber(getMinNumber(i1,i2),getMinNumber(i3,i4));

return iRtn;

}

public static int getMinNumber(int i1,int i2){

int iRtn = i1;

if (i1 > i2){

iRtn = i2;

}

return iRtn;

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航