Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
求Humble Numbers

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

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;
  }
}




相关文章

相关软件