Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define MAX 100000
- #define fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
- ll mini(ll a, ll b, ll c, ll d,ll e, ll f)
- {
- return min(a,min(b,min(c,min(d,min(e,f)))));
- }
- int main()
- {
- ll cnt=1,mn,ans;
- ll two=1, three=1,five=1,five_three=1,five_two=1,two_three=1,ct53=2,ct52=2,ct23=2;
- five_three*=15;
- five_two*=10;
- two_three*=6;
- two*=2;
- three*=3;
- five*=5;
- while(cnt<1500)
- {
- //cout<<"two ="<<two<<" three="<<three;
- mn=mini(two,two_three,three,five,five_three,five_two);
- if(mn==two)
- two*=2;
- else if(mn==three)
- three*=3;
- else if(mn==five)
- five*=5;
- else if(mn==five_three)
- {
- five_three*=ct53;
- ct53++;
- }
- else if(mn==five_two)
- {
- five_two*=ct52;
- ct52++;
- }
- else if(mn==two_three)
- {
- two_three*=ct23;
- ct23++;
- }
- ans=mn;
- cout<<ans<<" count = "<<cnt<<"\n";
- cnt++;
- }
- cout<<"The 1500'th ugly number is "<<ans<<".";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement