Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define MAX 100000
  5. #define fast ios_base::sync_with_stdio(false);cin.tie();cout.tie();
  6.  
  7. ll mini(ll a, ll b, ll c, ll d,ll e, ll f)
  8. {
  9.     return min(a,min(b,min(c,min(d,min(e,f)))));
  10. }
  11.  
  12. int main()
  13. {
  14.     ll cnt=1,mn,ans;
  15.     ll two=1, three=1,five=1,five_three=1,five_two=1,two_three=1,ct53=2,ct52=2,ct23=2;
  16.     five_three*=15;
  17.     five_two*=10;
  18.     two_three*=6;
  19.     two*=2;
  20.     three*=3;
  21.     five*=5;
  22.     while(cnt<1500)
  23.     {
  24.         //cout<<"two ="<<two<<" three="<<three;
  25.         mn=mini(two,two_three,three,five,five_three,five_two);
  26.         if(mn==two)
  27.             two*=2;
  28.         else if(mn==three)
  29.             three*=3;
  30.         else if(mn==five)
  31.             five*=5;
  32.         else if(mn==five_three)
  33.         {
  34.             five_three*=ct53;
  35.             ct53++;
  36.         }
  37.         else if(mn==five_two)
  38.         {
  39.             five_two*=ct52;
  40.             ct52++;
  41.         }
  42.         else if(mn==two_three)
  43.         {
  44.             two_three*=ct23;
  45.             ct23++;
  46.         }
  47.         ans=mn;
  48.         cout<<ans<<"   count = "<<cnt<<"\n";
  49.         cnt++;
  50.     }
  51.     cout<<"The 1500'th ugly number is "<<ans<<".";
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement