Ugly Numbers

Descriptions:

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, 15, ...
shows the first 11 ugly numbers. By convention, 1 is included.
Write a program to find and print the 1500’th ugly number.

Input

There is no input to this program

Output

Output should consist of a single line as shown below, with ‘’ replaced by the number computed. 

Sample Output

The 1500'th ugly number is <number>.
题意
丑数是指不能被2,3,5以外的其他素数整除的数。把丑数从小到大排列起来,结果如下:
1,2,3,4,5,6,8,9,10,12,15……
求第1500个丑数
输入
没有输入
输出
The 1500'th ugly number is <number>.

题目链接:

https://vjudge.net/problem/UVA-136

不难发现2,3,5之后的丑数全是有这三个数乘上{2,3,5}之后得来的,这就好办了,因为不可重复,还需要按顺序来,所以选择<set>是没有问题的,用<set>存入这些丑数,记录 it 的大小,当it为1500-1(数组从0开始计数)时就是我们要找的这个丑数

AC代码:

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define ll long long
#define INF 0x3f3f3f3f
#define ME0(x) memset(x,0,sizeof(x))
using namespace std;
set<ll> num;//存入丑数
set<ll>::iterator it;
int main()
{
int a[]= {,,};
num.insert();
int sum=;//这里面肯定会有重复的,所以要重新设一个计数器
it=num.begin();//从0开始计数
while(sum<-)//当然sum的值可以更大一点,这也没事,主要是去重复
{
for(int i=; i<; i++)
num.insert(*it * a[i]);
it++;//记录当前为第几个丑数
sum++;
}
printf("The 1500'th ugly number is %llu.\n", *it);
}


												

最新文章

  1. Js 遍历json对象所有key及根据动态key获取值
  2. iOS - Mac OS X 终端设置
  3. 数论 - 高精度Fibonacci数 --- UVa 10183 : How Many Fibs ?
  4. javascript中parentNode,childNodes,children的应用详解
  5. ORACLE用SYS登录报ORA-28009:connection as SYS should be as SYSDBA OR SYSOPER解决方法
  6. WaitForSingleObject与WaitForMultipleObjects用法详解(好用,而且进入一个非常高效沉睡状态,只占用极少的CPU时间片)
  7. 面试题:实现LRUCache::Least Recently Used的缩写,意思是最近最少使用,它是一种Cache替换算法
  8. Linux内核学习笔记3——分段机制和分页机制
  9. Android Wear和二维码
  10. 关于饿了么在浏览器标签页失去焦点时网页Title改变的实现方法
  11. [Micropython][ESP8266] TPYBoard V202 之MQTT协议接入OneNET云平台
  12. c#动态加载卸载DLL
  13. jmeter如何录制App及Web应用
  14. Windows10用fiddler抓包Android应用(解决手机设置代理后无法上网,设置只抓app包)
  15. 递归算法+sql三种分页
  16. python3 re模块
  17. Java框架spring 学习笔记(十):bean管理(注解和配置文件混合使用)
  18. idea出现找不到实体类
  19. Ajax之跨域请求
  20. mysql的密码问题

热门文章

  1. java--List判断是否为空
  2. 最短路径问题----Dijkstra算法的解释
  3. BZOJ 1609 [Usaco2008 Feb]Eating Together麻烦的聚餐:LIS &amp; LDS (nlogn)
  4. 51nod1671【货物运输】
  5. 天池历届大赛答辩PPT及视频
  6. Ubuntu下安装deb包命令
  7. 使用Tornado作为Django App的服务器
  8. poj2411铺砖——状压DP
  9. WPF GridViewColumn Sort DataTemplate
  10. &#39;ascii&#39; codec can&#39;t decode byte 0xe6 in position 0: ordinal not in range(128)