HDU ACM 1058

// ACM.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


#include<stdio.h>
#define M 5843
  
long a[M+4];

    long min(long x,long y)
    {
        if(x<=y)return x;
        else
            return y;
    }

    void choose()
    {
        int i,i1,i2,i3,i4;
        long t1,t2,t3,t4;
        a[0]=1;
        i1=0;i2=0;i3=0;i4=0;
        for(i=1;i<M;i++)   //很好用的打表技巧呢!
        {
            t1=a[i1]*2;   //对于表中的每一项,都乘以对应的素数,就不会漏掉数字了。^l^
            t2=a[i2]*3;
            t3=a[i3]*5;
            t4=a[i4]*7;
 
            a[i]=min(min(t1,t2),min(t3,t4));

            if(a[i]==t1)i1++;
            if(a[i]==t2)i2++;
            if(a[i]==t3)i3++;
            if(a[i]==t4)i4++;  //这里可不能用else,t1,t2,t3,t4可能相等的哦。
        }
    }

int main()
{
    int n,temp,st;
 
    choose();


    while(scanf("%d",&n),n)
    {

        temp=n%100;
        st=temp%10;

        if(st==1&&(temp!=11))
        {
            printf("The %dst humble number is %ld./n",n,a[n-1]);
        }

        else
            if(st==2&&temp!=12)
            {
                printf("The %dnd humble number is %ld./n",n,a[n-1]);
            }

        else
            if(st==3&&temp!=13)
            {
                printf("The %drd humble number is %ld./n",n,a[n-1]);
            }

        else
            printf("The %dth humble number is %ld./n",n,a[n-1]);

    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值