HDOJ1058固定质因子

24 篇文章 0 订阅
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<iostream>
const int inf = 0x3f3f3f;
using namespace std;
__int64 a[6000];
int mutiply(__int64 a[],int p,int r)//排序算法.
{
    int i = p - 1;
    int j = r + 1;
    __int64 x = a[p];
    while(1)
    {
        i++;
        while(a[i] < x)
          i++;
        j--;
        while(a[j] > x)
          j--;
        if(i < j)
        {
            __int64 ex;
            ex = a[i];
            a[i] = a[j];
            a[j] = ex;
        }
        else return j;


    }
}
void quicksort(__int64 a[],int p,int r)
{
    if(p < r)
    {
        int q = mutiply(a,p,r);
        quicksort(a,p,q);
        quicksort(a,q+1,r);
    }
}
int main()
{
    __int64 ans,maxx = 0;int t = 1;
    for(int i = 0 ; i<= 31 ;i++)//计算ans = 2^i*3^j*5^k*7^l的每一个数.即为满足条件的数.最后再2排序就OK了.
    {
        for(int j = 0 ; j <= 31 ; j++)
        {
            for(int k = 0 ; k <= 31 ; k++)
            {
                for(int l = 0 ; l <= 31 ; l++)
                {
                    bool vis = 0;
                    ans = 1;
                    for(int ss = 0 ; ss < i ; ss++)
                    {
                        ans *= 2;
                        if(ans > 2000000000)
                         vis = 1;
                    }
                    for(int ss = 0 ; ss < j ; ss++)
                    {
                        ans *= 3;
                        if(ans > 2000000000)
                          vis = 1;
                    }
                    for(int ss = 0 ; ss < k ; ss++)
                    {
                        ans *= 5;
                        if(ans > 2000000000)
                          vis = 1;
                    }
                    for(int ss = 0 ; ss < l ; ss++)
                    {
                        ans *= 7;
                        if(ans > 2000000000)
                          vis = 1;
                    }
                    if(!vis)
                    {
                        a[t++] = ans;
                    }
                    else break;
                }
            }
        }
    }
   quicksort(a,1,t-1);
   int n;
   while(scanf("%d",&n) && n!= 0)
   {
       if((n % 10 == 1 || n % 10 == 2 || n % 10 == 3 ) && n/10%10 == 1)
       printf("The %dth humble number is %I64d.\n",n,a[n]);
       else
       {
           if(n % 10 == 3)
           printf("The %drd humble number is %I64d.\n",n,a[n]);
           if(n % 10 == 2)
           printf("The %dnd humble number is %I64d.\n",n,a[n]);
           if(n % 10 == 1)
           printf("The %dst humble number is %I64d.\n",n,a[n]);
           if(n % 10 != 3 && n % 10 != 2 && n % 10 != 1)
           printf("The %dth humble number is %I64d.\n",n,a[n]);
       }
   }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值