STL UVA-136 Ugly Numbers Set

9 篇文章 0 订阅

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 .

 

丑数,因子只有2、3、5,一开始每个数都除到1的辣鸡方法,自然是T了。(其实最最最开始是读错题了hhh

后来就从前往后递推这样子(很多地方都有用到这样的方法叭

(中间还用过愚蠢而没有必要的优先队列

放入set里,自动排序,自动去重,简直如同父母的乖宝宝

最后一直WA因为没有打换行符???!心态崩了,问问问.jpg

 

#include <cstdio>
#include <queue>
#include <set>
using namespace std;

int main()
{
	set <long long> s;
	s.insert(1);
	set <long long>::iterator it=s.begin();
	long long i=0,x;

	while(i<1500){
		x=*it;
		s.insert(x*2);
		s.insert(x*3);
		s.insert(x*5);
		it++;i++;
	}
	printf("The 1500'th ugly number is %lld.\n",x);

	return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值