Save Princess(丑数)

时间:2022-09-03 21:43:30

Save Princess

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
 
描述
Yesterday, the princess was kidnapped by a devil. The prince has to rescue our pretty princess.
 
"OK, if you want to save the beautiful princess, you must answer my questions correctly."the devil says.
 
"No problem!".
 
"I’ll ask you t questions. For each question, I’ll tell you an integer n, you must tell me the i th beatuiful number. If your answer is wrong, the princess and you will all die".
 
"But what is the characteristic of the beautiful number?" Pince asks.
 
"Beautiful numbers are numbers whose only prime factors are 2, 3 or 5. The sequence
1, 2, 3, 4, 5, 6, 8, 9, 10, ...   shows the first 9 beautiful numbers. 
By convention, 1 is included. "
 
Can you help the prince to save the princess?
 
输入
The input for each case is an integer n(1≤n≤5000) and it is terminated by a negative integer.
输出
For each test case, you should print an integer which represents the i th beautiful number.
样例输入
2
3
-1
样例输出
2
3

题解:这个方法解决丑数非常实用;

代码:

 #include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=;
typedef long long LL;
LL ans[MAXN];
LL MIN(LL x,LL y,LL z){
LL d=x;
if(y<d)d=y;
if(z<d)d=z;
return d;
}
int main(){
int n,x_2=,x_3=,x_5=;
LL d;
ans[]=;
int i=;
while(i<=){
i++;
d=MIN(ans[x_2]*,ans[x_3]*,ans[x_5]*);
ans[i]=d;
if(d==ans[x_2]*)x_2++;
if(d==ans[x_3]*)x_3++;
if(d==ans[x_5]*)x_5++;
}
while(scanf("%d",&n),n>)printf("%lld\n",ans[n]);
return ;
}

Save Princess(丑数)的更多相关文章

  1. nyoj1032——Save Princess——————【set应用】

    Save Princess 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Yesterday, the princess was kidnapped by a de ...

  2. AC日记——丑数 codevs 1246

    1246 丑数 USACO  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 Description 对于一给定的素 ...

  3. 剑指Offer面试题:29&period;丑数

    一.题目:丑数 题目:我们把只包含因子2.3和5的数称作丑数(Ugly Number).求按从小到大的顺序的第1500个丑数.例如6.8都是丑数,但14不是,因为它包含因子7.习惯上我们把1当做第一个 ...

  4. 剑指Offer&colon;面试题34——丑数&lpar;java实现&rpar;

    问题描述: 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 思路1: ...

  5. UVA136 求第1500个丑数

    枚举大范围数据..暴力检查题目条件 #include <iostream> #include <cstdio> #include <vector> #include ...

  6. 37&period;寻找丑数&lbrack;Ugly numbers&rsqb;

    [题目] 我们把只包含质因子2.3和5的数称作丑数(Ugly Number),例如:2,3,4,5,6,8,9,10,12,15,等,习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第1500个丑 ...

  7. hdu1058丑数(优先队列、暴力打表)

    hdu1058 题意:当一个数只有2.3.5.7这四种质因数时(也可以一种都没有或只有其中几种),这个数就是丑数,输出第 n 个丑数是多少: 其实并没有发现hdu把这道题放在 dp 专题里的意图,我的 ...

  8. 剑指offer系列59---寻找丑数

    [题目]把只包含因子2.3和5的数称作丑数(Ugly Number). * 例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 解法一 ...

  9. 洛谷P2723 丑数 Humble Numbers

    P2723 丑数 Humble Numbers 52通过 138提交 题目提供者该用户不存在 标签USACO 难度普及/提高- 提交  讨论  题解 最新讨论 暂时没有讨论 题目背景 对于一给定的素数 ...

随机推荐

  1. 一款简洁大气的jquery日期日历插件

    本jquery插件名为manhuaDate,暂时只支持jquery 1.9.0以下版本,比如jquery-1.8.3.min.js 查看效果网址:http://keleyi.com/a/bjad/em ...

  2. IOS 支付、性能调试、IPv6兼容支持等

    微信支付 支付宝支付 性能调试 IPv6兼容支持 APP引导页框架

  3. 1763 An Essay towards solving a Problem in the Doctrine of Chances

    https://en.wikipedia.org/wiki/An_Essay_towards_solving_a_Problem_in_the_Doctrine_of_Chances

  4. &lbrack;转&rsqb;C&plus;&plus;宏定义详解

    一.#define的基本用法     #define是C语言中提供的宏定义命令,其主要目的是为程序员在编程时提供一定的方便,并能在一定程度上提高程序的运行效率,但学生在学习时往往不能 理解该命令的本质 ...

  5. 【ecos学习1】wmware运行redboot&lbrack;方法一&rsqb;--脚本实现配置

    背景: 远程服务器Ubuntu生成软盘镜像,通过Mac下wmware运行. 1- 环境及版本: uname -a 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 ...

  6. alt&plus;shift&plus;j,添加日期、作者等

    在preference->Java->codestyle->codetemplates->commnets->type 可以编辑如: /** * @author ${us ...

  7. JDBC整合c3p0数据库连接池 解决Too many connections错误

    前段时间,接手一个项目使用的是原始的jdbc作为数据库的访问,发布到服务器上在运行了一段时间之后总是会出现无法访问的情况,登录到服务器,查看tomcat日志发现总是报如下的错误. Caused by: ...

  8. Android WebView 调试方法

    调试Android WebView中的h5页面,通常就是通过alert和抓包工具来定位问题,效率低且无法直接调试样式或打断点,可谓是事倍功半.本文介绍一下我在项目中使用的新方法,能够通过chrome的 ...

  9. Linux权限分析

    我看过网上的一些有关Linux的权限分析,有些说的不够清楚,另外一些说的又太复杂.这里我尽量简单.清楚的把Linux权限问题阐述明白,Linux权限没有那么复杂. Linux权限问题要区分文件权限和目 ...

  10. python之路day09--函数

    s='金老板啊'print(len(s)) #内置函数 s='金老板啊'# def my_len():# i=0# for k in s:# i+=1# # print(i)# print(my_le ...