hdu 1058 枚举法

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#define UP 2000000000L
#define MAX 160007

using namespace std;

typedef long long LL;

LL num[MAX];
int cnt = 1;

void init ( )
{
    LL temp1 = 1 , temp2 = 1 , temp3 = 1 , temp4 = 1;
    while ( temp1 <= UP )
    {
        temp2 = 1;
        while ( temp2 <= UP )
        {
            temp3 = 1;
            if ( temp1 * temp2 > UP ) break;
            while ( temp3 <= UP )
            {
                if ( temp1 * temp2 * temp3 > UP ) break;
                temp4 = 1;
                while ( temp4 <= UP )
                {
                    if ( temp1 * temp2 * temp3 * temp4 > UP ) break;
                    num[cnt++] = temp1 * temp2 * temp3 * temp4;
                    temp4 *= 2;
                }
                temp3 *= 3;
            }
            temp2 *= 5;
        }
        temp1 *= 7;
    }
    sort ( num+1 , num + cnt ); 
}

int main ( )
{
    int n;
    init ( );
    while ( ~scanf ( "%d" , &n ), n  )
    {
        char s[50];
        if ( (n/10)%10 != 1 )
        {
            if ( n%10 == 1 ) sscanf ( "st" , "%s" , s );
            else if ( n%10 == 2 ) sscanf ( "nd" , "%s" , s );
            else if ( n%10 == 3 ) sscanf ( "rd" , "%s" , s );
            else sscanf ( "th" , "%s" , s );
        }
        else  sscanf ( "th" , "%s" , s );
        printf ( "The %d%s humble number is %lld.\n" , n , s ,num[n] ); 
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值