## problem 136

Moderator: Board moderators

### problem 136

is this correct the 1500th ugly number is 2999.
here is code where is error;
#include<stdio.h>
#include<iostream>
#include<vector>
using namespace std;
vector<long>ugly;
vector<long>list;
vector<long>::iterator it;
vector<long>::iterator u;

void primegenerate(long n)
{

//list.push_back(2);
for(long i=7;i<=n;i+=2)
{
list.push_back(i);//list create
}
for(long p=3;p*p<=n;p+=2)
{
for(it=list.begin()+1;it<list.end();)
{
if(*it%p==0 && *it!=p)
{
list.erase(it);//erase

}
else
it++;
}
}

i=0;
/*for(it=list.begin();it<list.end();it++,i++)
{
cout<<i<<" "<<list[i]<<" ";
}*/
}

void print(int number)
{
//int i=0;
u=ugly.begin();
u=u+number-1;
cout<<"The "<<number<<"th ugly nmber is "<<*u;
// for(it=ugly.begin();it<ugly.end(),i<1500;it++,i++)
// {cout<<i<<" "<<*it<<endl;
// }
}

int main()
{
int counter=0;

for(long i=7;i<3000;i++)
{
if(i%2||i%3||i%5)
{

ugly.push_back(i);

//cout<<ugly[counter]<<" ";
counter++;}

}
cout<<counter;

primegenerate(1600);

//cout<<list.size();
long num,den;
u=ugly.begin();
for(u=ugly.begin();u<ugly.end();)
{
for(it=list.begin();(*it)*(*it)<=(*u)||it<list.end();it++)
{
num=*u;den=*it;
if(num%den==0)
{
ugly.erase(u);//erase
break;
}

}
u++;
}

//int number;
//while(1){

u=ugly.begin();
for(i=1;i<=6;i++)
{
ugly.insert(u,1,i);
u++;
}
//while(1){
//cin>>number;

print(1500);
//cout<<ugly.size()<<" "<<ugly[1500];

return 0;
}
u can mail me at mahmed0715@yahoo.com
mustak0715
New poster

Posts: 3
Joined: Tue Oct 26, 2010 3:42 am

### Re: problem 136

no.. try again..it is bigger than your ans....
shiam
New poster

Posts: 3
Joined: Mon Mar 14, 2011 6:44 am