栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

【UJN-寒假练练练】新年快乐-3--枚举

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

【UJN-寒假练练练】新年快乐-3--枚举

//
R - Ugly Numbers

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

//
题意:只含有质因数 2 3 5 的数为丑数 求第 n 个丑数
//
题解:
01 由 素数分解唯一定理 可知 丑数的质因子只能有 2 3 5 
02 要求丑数的位次 通过比较最小值 打表

// 判断是否为丑数
bool is_ugly( int n )
{
    if( n<=0 ) return false;
    while( n%2==0 ) n/=2;
    while( n%3==0 ) n/=3;
    while( n%5==0 ) n/=5;
    return n==1;            // 返回语句真假值
}

// 丑数打表
#include
using namespace std;

typedef unsigned long long ull;
const int MAXN=1e4+5;

int ans[MAXN];

int my_min( int a,int b,int c )
{
    int temp=a 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/717314.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号