Poj 2247 humble numbers

Source: Internet
Author: User


Humble numbers
Time limit:1000 ms   Memory limit:65536 K
Total submissions:9453   Accepted:4440

Find out the numbers of all the factors that are only 2, 3, 5, and 7, give n, and find the nth number. In this case, only 6000 is not used in the table.

Note that the output of 11th 12 13 is different from the output of 1 2 3, and.



#include <iostream>#include <algorithm>using namespace std;long humble[6000];int main(){    int i, n2, n3, n5, n7;    humble[1] = 1;    n2 = 1;    n3 = 1;    n5 = 1;    n7 = 1;    for (i = 2; i <= 5900; i++)    {        humble[i] = min(min(humble[n2]*2, humble[n3]*3), min(humble[n5]*5, humble[n7]*7));        if (humble[i] == humble[n2]*2)            n2++;        if (humble[i] == humble[n3]*3)            n3++;        if (humble[i] == humble[n5]*5)            n5++;        if (humble[i] == humble[n7]*7)            n7++;    }        int num;    while (cin >> num && num)    {          int tmp1, tmp2;          tmp1 = num % 10;          tmp2 = num % 100;          if (tmp1 == 1)          {             if (tmp2 == 11)                 cout << "The " << num << "th humble number is " << humble[num] << "." << endl;             else                  cout << "The " << num << "st humble number is " << humble[num] << "." << endl;          }          else if (tmp1 == 2)          {             if (tmp2 == 12)                 cout << "The " << num << "th humble number is " << humble[num] << "." << endl;             else                 cout << "The " << num << "nd humble number is " << humble[num] << "." << endl;          }          else if (tmp1 == 3)          {             if (tmp2 == 13)                 cout << "The " << num << "th humble number is " << humble[num] << "." << endl;             else                 cout << "The " << num << "rd humble number is " << humble[num] << "." << endl;          }          else              cout << "The " << num << "th humble number is " << humble[num] << "." << endl;    }        system("pause");}


Poj 2247 humble numbers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.