Here only one number is needed to print. So I use pre-calculation. The code
that I use for pre-calculation is as follows.
main(void)
{
unsigned long int pos=11,_num=15,num,i=1;
while(pos<1500)
{
_num++;
num=_num;
while(!(num%5))
num /=5; while(!(num%3))
num /=3;
while(!(num&1))
num >>=1;
if(num==1)
{ pos++;
if((i*100)<pos)
i++;
gotoxy(20,0+i);
cout<< pos<< " th ugly num is " << _num;
}
}
cout << "The 1500'th ugly number is
"<<_num;
getch();
return 0;
}
The number is 859963392
Don�t cheat with
yourself. |