Problem3-1004

简单题意:

许多的唯一主要因素是2,3,5或7被称为一个不起眼的数字。序列1,2,3,4,5,6,7,8,9,10,12,14,15,16,18,20,21,24,25,27,...示出第一20谦虚数字。搜索结果编写一个程序,发现在这个顺序打印第n个元素结果

解题思路:

谦卑number从1为"始祖",剩下的所有数,其实都是在此基础上乘以2,3,5,7演化出来的,:f[t]=min(2*f[i],3*f[j],5*f[k],7*f[l]); 

代码如下:
#include <iostream>
#include <cstdio>


using namespace std;


const int maxn = 5843;
int humber[maxn];


void prepare() {
    int i;
    humber[1] = 1;
    int na;
    int nb;
    int nc;
    int nd;
    int pos1 = 1;
    int pos2 = 1;
    int pos3 = 1;
    int pos4 = 1;


    for (i = 2; i <= maxn; ++i) {
        //从符合要求的数中找到最小的那个数作为目前humber数
        humber[i] = min(min(na = humber[pos1] * 2,nb = humber[pos2] * 3),
                        min(nc = humber[pos3] * 5, nd = humber[pos4] * 7));


        if (humber[i] == na) {//如果选择了这个因子,则将起索引向后移一位
            pos1++;
        }
        if (humber[i] == nb) {
            pos2++;
        }
        if (humber[i] == nc) {
            pos3++;
        }
        if(humber[i] == nd){
            pos4++;
        }


    }
}


int main() {
    prepare();
    int n;
    while (scanf("%d", &n) != EOF, n) {
         printf("The %d",n);


        if (n % 100 != 11 && n % 10 == 1){
            printf("st");
        }else if (n % 100 != 12 && n % 10 == 2){
            printf("nd");
        }else if (n % 100 != 13 && n % 10 == 3){
            printf("rd");
        }else{
            printf("th");
        }
        printf(" humble number is %d.\n",humber[n]);
    }


    return 0;
}







### 关于Codeforces平台编号为1004的比赛题目详情 对于编号为1004的具体比赛题目,在给定的信息中并没有直接提及该编号的相关细节。然而,通常情况下,Codeforces上的每场比赛问题都有详细的描述页面,其中包括题目列表、提交记录以及讨论区等内容。 为了获取关于编号为1004的确切信息,建议访问Codeforces官方网站并搜索对应编号的比赛题目[^1]。通过这种方式可以找到最准确和最新的资料。如果这是个特定的比赛,则其URL可能类似于`https://codeforces.com/contest/1004`;如果是某个具体的问题,则可能是像`https://codeforces.com/problemset/problem/1004/A`这样的形式[^2]。 另外值得注意的是,Codeforces会定期举办不同类型的竞赛活动,包括常规赛、教育赛以及其他特别赛事。因此,了解具体的上下文有助于更精确地定位所需资源。例如,某些特殊日期举办的愚人节大赛也会有独特的编号体系[^3]。 ```python import requests from bs4 import BeautifulSoup def get_contest_info(contest_id): url = f"https://codeforces.com/contest/{contest_id}" response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.text, &#39;html.parser&#39;) title_tag = soup.find(&#39;div&#39;, class_=&#39;title&#39;).find_next_sibling(&#39;div&#39;) problems_section = soup.find(id=&#39;problems-section&#39;) print(f"Title: {title_tag.text.strip()}") print("Problems:") for row in problems_section.select(&#39;.problemindexholder tr&#39;)[1:]: cols = row.select(&#39;td&#39;) index = cols[0].text.strip() name = cols[1].a[&#39;href&#39;].split(&#39;/&#39;)[-1] points = cols[-1].text.strip() print(f"{index}: {name} ({points})") get_contest_info(1004) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值