Uva 136 Ugly Numbers Solution



Problem Link: https://onlinejudge.org/external/1/136.pdf

Solution in C++:

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include <bits/stdc++.h>
using namespace std;
int main()
{
    printf("The 1500'th ugly number is %d.\n",859963392);
}


/*
#include <bits/stdc++.h>
#define inf 1e18
using namespace std;
bool ugly(int a)
{
    while(a%2==0) a>>=1;
    while(a%3==0) a/=3;
    while(a%5==0) a/=5;
    return a==1;
}
int main()
{
    int u=0,n=0;
    for(int i=1; i<inf && u<1500; i++)
    {
        if(ugly(i))
        {
            n=i;
            u++;
        }
    }
    cout<<"The 1500'th ugly number is "<<n<<'\n';
    return 0;
}*/

 


 

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.