【UVA - 136】Ugly Numbers(set)
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);
}
【UVA - 136】Ugly Numbers(set)的更多相关文章
- 【例题5-7 UVA - 136】Ugly Numbers
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 每个丑数x,都能生成3个丑数2x,3x,5x 则我们以1作为起点. 生成丑数. 每次取出set里面最小的那个数. 然后用它去生成其他 ...
- 【UVA - 10006 】Carmichael Numbers (快速幂+素数筛法)
-->Carmichael Numbers Descriptions: 题目很长,基本没用,大致题意如下 给定一个数n,n是合数且对于任意的1 < a < n都有a的n次方模n等于 ...
- 【UVA 10369】 Arctic Network (最小生成树)
[题意] 南极有n个科研站, 要把这些站用卫星或者无线电连接起来,使得任意两个都能直接或者间接相连.任意两个都有安装卫星设备的,都可以直接通过卫星通信,不管它们距离有多远. 而安装有无线电设备的两个站 ...
- 【UVA 11462】 Age Sort(基数排序)
题 题意 给你最多2000000个数据,大小是1到99的数,让你排序输出. 分析 快排也可以过.不过这题本意是要基数排序(桶排序),就是读入年龄age, a[age]++,然后输出时,从1到99岁(看 ...
- 【UVA 11426】gcd之和 (改编)
题面 \(\sum_{i=1}^{n}\sum_{j=1}^m\gcd(i,j)\mod998244353\) \(n,m<=10^7\) Sol 简单的一道莫比乌斯反演题 \(原式=\sum_ ...
- 【CF55D】Beautiful numbers(动态规划)
[CF55D]Beautiful numbers(动态规划) 题面 洛谷 CF 题解 数位\(dp\) 如果当前数能够被它所有数位整除,意味着它能够被所有数位的\(lcm\)整除. 所以\(dp\)的 ...
- 【Win10 UWP】QQ SDK(二):SDK的回调处理
上一讲,我们介绍了QQ SDK的使用方法,请看<[Win10 UWP]QQ SDK(一):SDK基本使用方法> 一. 回调的基本形式 从前面的介绍中我们知道,我们的应用和QQ客户端之间需要 ...
- 【Win10 UWP】QQ SDK(一):SDK基本使用方法
每当开发一个应用需要社交分享的应用时,总是心里咯噔一下:到底什么时候分享能加上QQ和微信?除了WP8.0版本的微信SDK,官方似乎从未正面发布过适应时代发展的QQ SDK,就连后台,也没有一个可以创建 ...
- 【UOJ#242】【UR#16】破坏蛋糕(计算几何)
[UOJ#242][UR#16]破坏蛋糕(计算几何) 题面 UOJ 题解 为了方便,我们假定最后一条直线是从上往下穿过来的,比如说把它当成坐标系的\(y\)轴. 于是我们可以处理出所有交点,然后把它们 ...
随机推荐
- 5.1 《锋利的jQuery》jQuery对表单的操作
获取焦点和失去焦点改变样式 改变文本框/滚动条高度 复选框应用 下拉框应用 表单验证 tip1: 注意使用<label>的for标签,对应input的id.(for 属性规定 label ...
- HDU2825 Wireless Password —— AC自动机 + 状压DP
题目链接:https://vjudge.net/problem/HDU-2825 Wireless Password Time Limit: 2000/1000 MS (Java/Others) ...
- (1)WEB框架概念和struts2体验
Struts快速入门 day31 1.相关jar包 Struts2-core-lib(Struts2 的核心jar包) 代理的两种方式 JDK(简单,不稳定)和第三方 javaassist包——动态代 ...
- ffmpeg 调试
--enable-debug=3 --disable-optimizations --disable-yasm --disable-asm
- hdu5776sum
题目连接 抽屉原理:如果现在有3个苹果,放进2个抽屉,那么至少有一个抽屉里面会有两个苹果 抽屉原理的运用 现在假设有一个正整数序列a1,a2,a3,a4.....an,试证明我们一定能够找到一段连续 ...
- L90
On Motes and Beams 微尘与栋梁 It is curious that our own offenses should seem so much less heinous than t ...
- 机器学习:simple linear iterative clustering (SLIC) 算法
图像分割是图像处理,计算机视觉领域里非常基础,非常重要的一个应用.今天介绍一种高效的分割算法,即 simple linear iterative clustering (SLIC) 算法,顾名思义,这 ...
- 1080 Graduate Admission (30)(30 分)
It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applicat ...
- 二:apache的Qpid消息中间件介绍
一:什么是Qpid?--->Qpid 是 Apache 开发的一款面向对象的消息中间件,它是一个 AMQP 的实现,可以和其他符合 AMQP 协议的系统进行通信.--->Qpid 提供了 ...
- tyvj1659救援队——最小生成树
题目:http://www.joyoi.cn/problem/tyvj-1659 想清楚了是非常简单的最小生成树: 1.树中每条边都会被走两边: 2.每个点会走度数遍,起点又多走一遍: 根据以上两条处 ...