UVa 136 – Ugly Numbers


/*
User ID: turing_13
Link : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=72
*/

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int main()
{
    double a,b,c,k,ara[2000];
    int count=0;
    for(a=0; a<31; a++)
        for(b=0; b<31; b++)
            for(c=0; c<31; c++)
            {
                k=pow(2,c)*pow(3,b)*pow(5,a);
                if(k>1000000000)
                {
                    k=0;
                      break;
                }
                else
                {
                    ara[count]=k;
                    count++;
                }
            }
    sort(ara,ara+count);
    printf("The 1500'th ugly number is %.lf.\n",ara[1499]);
    return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s