zoukankan      html  css  js  c++  java
  • poj 2247 Humble Numbers


    Humble Numbers
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 9453   Accepted: 4440

    题目大意:找出全部因子中仅仅有2,3,5,7的数。给出n,求出第n个这样   仅仅有6000不到打表

    注意第11  12  13 的输出与 1   2   3    几十一   几十二   几十三 的输出不同  



    #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");
    }


  • 相关阅读:
    [UE4]roll pitch yaw
    [UE4]用向量表示方向
    [UE4]关闭自动曝光
    Mysql数据库常用分库和分表方式
    mycat分库分表 mod-long
    windows安装mycat(转)
    Mycat读写分离、主从切换学习(转)
    Windows版Mycat结合mysql安装配置+水平切分(转载)
    数据库高性能读写分离集群操作说明
    spring MVC、mybatis配置读写分离,ReplicationDriver(转载)
  • 原文地址:https://www.cnblogs.com/mthoutai/p/6862636.html
Copyright © 2011-2022 走看看