题意
丑数是指不能被2,3,5以外的其他素数整除的数。把丑数从小到大排列起来,结果如下:
1,2,3,4,5,6,8,9,10,12,15……
求第1500个丑数
输入
没有输入
输出
The 1500'th ugly number is <number>.
这道题是求第1500个丑数,因为根据定义丑数只能是2,3,5的倍数,所以从第一个丑数开始,每次拿这个丑数乘2,3,5就可以得到新的丑数,因此只要把1500+个丑数生成出来并排好序,然后找第1500个,正好set有自动去重排序的功能,所以可以直接把每次生成的丑数放在set中就行了。
完整代码:
#include <bits/stdc++.h>
#define int long long
using namespace std;
set<int>s;
int chou[3]={2,3,5};
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
s.insert(1);
set<int>::iterator it;
int cnt=1;
while(cnt<=1800)
{
for(it=s.begin();it!=s.end()&&cnt<=1800;it+&#