丑数,4遍提交耻辱啊。
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 ‘< number >’ replaced by the number
computed.
Sample Output
The 1500’th ugly number is < number >.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
int main()
{
set<int> a;
set<int> b;
set<int>::iterator p1,p2;
a.insert(1);
a.insert(2);
a.insert(3);
a.insert(4);
a.insert(5);
a.insert(6);
a.insert(8);
a.insert(9);
for(p1=a.begin();p1!=a.end();p1++)
{
a.insert(*p1*2);
a.insert(*p1*3);
a.insert(*p1*5);
if(a.size()>1600) break;
}
p1=a.begin();
for(int i=1;i<1500;i++)
{
p1++;
}
printf("The 1500'th ugly number is %d.\n",*p1);
}
算出来的数,跟网上查的是一样的,四遍就是过不去,后来发现,自己“ 点 ”的位置不对。换行符没加。活该不对。