• Ugly Numbers


    Ugly Numbers
    Time Limit: 1000MS Memory Limit: 10000K
    Total Submissions: 21918 Accepted: 9788

    Description
    Ugly numbers are numbers whose only prime factors are 2, 3 or 5. The sequence
    1, 2, 3, 4, 5, 6, 8, 9, 10, 12, …
    shows the first 10 ugly numbers. By convention, 1 is included.
    Given the integer n,write a program to find and print the n’th ugly number.

    Input
    Each line of the input contains a postisive integer n (n <= 1500).Input is terminated by a line with n=0.

    Output
    For each line, output the n’th ugly number .:Don’t deal with the line with n=0.

    Sample Input

    1
    2
    9
    0

    Sample Output

    1
    2
    10

    Source
    New Zealand 1990 Division I,UVA 136
    打表记录即可

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #define LL long long
    using namespace std;
    
    const LL MAX = 1e15;
    
    LL a[15500];
    int main()
    {
        LL b,c,d;
        int top=0;
        //freopen("output.txt","w",stdout);
        for(int i=0;i<=30;i++)
        {
            if(i==0)
            {
                b=1;
            }
            else
            {
                b*=2;
            }
            if(b>MAX)
            {
                break;
            }
            for(int j=0;j<=30;j++)
            {
                if(j==0)
                {
                    c=1;
    
                }
                else
                {
                    c*=3;
                }
                if(b*c>MAX)
                {
                    break;
                }
                for(int k=0;k<=30;k++)
                {
                    if(k==0)
                    {
                        d=1;
                    }
                    else
                    {
                        d*=5;
                    }
                    if(b*c*d>MAX)
                    {
                        break;
                    }
                    a[top++]=b*c*d;
                    //printf("%lld
    ",b*c*d);
                }
            }
        }
        sort(a,a+top);
        int n;
        while(scanf("%d",&n)&&n)
        {
            printf("%lld
    ",a[n-1]);
        }
        return 0;
    }
    
  • 相关阅读:
    vue loading 插件编写与实战
    vue tab切换的几种方式
    IOS安卓常见问题
    vue.js 跨域的解决方法(转载)
    vue 根据设计稿rem适配
    vuex 文件夹目录整理
    vue项目优化之路由懒加载
    flutter 环境配置-01
    锚点 定位 导航 滑动
    居中 子元素无固定 宽高
  • 原文地址:https://www.cnblogs.com/juechen/p/5255998.html
Copyright © 2020-2023  润新知