• 1004


    题目大意:

    有几个数,他们是2,3,5,7的倍数,把这些数排列出来,顺序输出规定的第几个数

    解题思路:

    先计算出最前的数,乘2,乘3,乘5,乘7,求出来这里面最小的,把最小的写入数组

    代码:

    #include <iostream>  
    #include <cstdio>  
    using namespace std;  
    long long dp[5843];  
    long long min(long long a, long long b, long long c, long long d)  
    {  
        long long temp1 = a < b ? a : b;  
        temp1 = temp1 < c ? temp1 : c;  
        temp1 = temp1 < d ? temp1 : d;  
        return temp1;  
    }  
    int main()  
    {  
          
        dp[1] = 1;  
        int a = 1, b = 1, c = 1, d = 1;  
        for (int i = 2; i <= 5842; ++i)  
        {  
            dp[i] = min(dp[a] * 2, dp[b] * 3, dp[c] * 5, dp[d] * 7);  
            if (dp[i] == dp[a] * 2) a++;  
            if (dp[i] == dp[b] * 3) b++;  
            if (dp[i] == dp[c] * 5) c++;  
            if (dp[i] == dp[d] * 7) d++;  
        }  
        int n;  
        while (cin>>n&&n)  
        {  
            if (n % 100 != 11 && n % 10 == 1)printf("The %dst humble number is %lld.
    ", n, dp[n]);  
            else  
                if (n % 100 != 12 && n % 10 == 2)printf("The %dnd humble number is %lld.
    ", n, dp[n]);  
                else  
                    if (n % 100 != 13 && n % 10 == 3)printf("The %drd humble number is %lld.
    ", n, dp[n]);  
                    else  
                        printf("The %dth humble number is %lld.
    ", n, dp[n]);  
        }  
        return 0;  
    }  
  • 相关阅读:
    前端知识点(1)
    js防抖和节流
    react生命周期方法有哪些?
    vue音乐播放器
    vue天气查询
    vue+axios安装
    vue 实现todolist,包含添加,删除,统计,清空,隐藏功能
    vue简单计数器
    手动搭建的react环境中,关于图片引入的问题
    promise封装ajax
  • 原文地址:https://www.cnblogs.com/Sikaozhe/p/5535142.html
Copyright © 2020-2023  润新知