杭电1058 喜欢ヅ旅行 2022-09-17 05:25 133阅读 0赞 # Humble Numbers # **Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13689 Accepted Submission(s): 5956** Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, ... shows the first 20 humble numbers. Write a program to find and print the nth element in this sequence Input The input consists of one or more test cases. Each test case consists of one integer n with 1 <= n <= 5842. Input is terminated by a value of zero (0) for n. Output For each test case, print one line saying "The nth humble number is number.". Depending on the value of n, the correct suffix "st", "nd", "rd", or "th" for the ordinal number nth has to be used like it is shown in the sample output. Sample Input 1 2 3 4 11 12 13 21 22 23 100 1000 5842 0 Sample Output The 1st humble number is 1. The 2nd humble number is 2. The 3rd humble number is 3. The 4th humble number is 4. The 11th humble number is 12. The 12th humble number is 14. The 13th humble number is 15. The 21st humble number is 28. The 22nd humble number is 30. The 23rd humble number is 32. The 100th humble number is 450. The 1000th humble number is 385875. The 5842nd humble number is 2000000000. 代码如下: #include <iostream> #include <algorithm> using namespace std; #define N 5842 int values[N + 1] ; inline int minValue(int n1, int n2, int n3, int n4) { return min(min(n1, n2), min(n3, n4)) ; } int main(int argc, char ** argv) { memset(values, 0, ( N + 1 ) * sizeof(int)) ; values[1] = 1 ; int p1, p2, p3, p4 ; p1 = p2 = p3 = p4 = 1 ; for (int i = 2; i <= N; ++ i) { values[i] = minValue(values[p1] * 2, values[p2] * 3, values[p3] * 5, values[p4] * 7) ; if (values[p1] * 2 == values[i]) p1 ++ ; if (values[p2] * 3 == values[i]) p2 ++ ; if (values[p3] * 5 == values[i]) p3 ++ ; if (values[p4] * 7 == values[i]) p4 ++ ; } int inValue ; while(cin >> inValue && inValue != 0) { if (inValue % 100 == 11 || inValue % 100 == 12 || inValue % 100 == 13) cout << "The "<< inValue << "th humble number is " <<values[inValue]<< "." << endl; else if (inValue % 10 == 1) cout << "The "<< inValue << "st humble number is " <<values[inValue]<< "." << endl; else if (inValue % 10 == 2) cout << "The "<< inValue << "nd humble number is " <<values[inValue]<< "." << endl; else if (inValue % 10 == 3) cout << "The "<< inValue << "rd humble number is " <<values[inValue]<< "." << endl; else cout << "The "<< inValue << "th humble number is " <<values[inValue]<< "." << endl; } return 0 ; }
相关 杭电1061 Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J 布满荆棘的人生/ 2022年09月17日 05:27/ 0 赞/ 282 阅读
相关 杭电1058 Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja 喜欢ヅ旅行/ 2022年09月17日 05:25/ 0 赞/ 134 阅读
相关 杭电1039 Easier Done Than Said? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553 一时失言乱红尘/ 2022年06月05日 12:48/ 0 赞/ 287 阅读
相关 杭电1026 Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6553 快来打我*/ 2022年06月04日 05:53/ 0 赞/ 306 阅读
相关 杭电oj Problem Title 2 Pro. ID 1001 Sum Problem include<stdio.h> int main() { 缺乏、安全感/ 2022年05月15日 16:18/ 0 赞/ 267 阅读
相关 杭电oj Problem Title 1 Pro. ID 1000 A+B Problem include<stdio.h> int main() { £神魔★判官ぃ/ 2022年05月15日 16:14/ 0 赞/ 334 阅读
相关 杭电1060 此题是一道数学题,也是一道技巧题,也是不能直接算的,否则会超时的!!! 此题思路: 设n^n=d.xxxx\10^(k-1),其中k表示n^n的位数; d.xxxx 痛定思痛。/ 2021年12月01日 22:40/ 0 赞/ 326 阅读
相关 杭电2075 此题真的是简单的再不能简单了!呵呵!我一直纠结,出这样的题是什么意思呢?不懂!哎,不说那些废话了,直接 ac吧!呵呵! \include<iostream> using 今天药忘吃喽~/ 2021年12月01日 22:38/ 0 赞/ 310 阅读
相关 杭电2078 说实话,此题是一道有严重bug的问题,对于xhd没晚能复习的科目数m根本就没用上!!!哎不管那么些了,反正ac了!呵呵!此题这样想xhd得复习效率是前一课程和后一课程复习效率差 ╰+攻爆jí腚メ/ 2021年12月01日 22:38/ 0 赞/ 354 阅读
相关 杭电2090 此题就是一道令人无法琢磨的题!哎!!我简直就无语了!!呵呵!竟然能出这题。。。。 废话少说,直接ac!!! \\\ 此题要想输出结果,还需要注意一下! 在linux 约定不等于承诺〃/ 2021年12月01日 21:12/ 0 赞/ 368 阅读
还没有评论,来说两句吧...