Advertisement
erfanul007

UVa 443

Apr 12th, 2019
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long int ll;
  5. #define read() freopen("input.txt", "r", stdin)
  6. #define write() freopen("output.txt", "w", stdout)
  7.  
  8. ll mx = 2000000009;
  9. vector<ll>humble;
  10. map<ll,bool>mp;
  11. int a[4]={2,3,5,7};
  12.  
  13. void gethumble(ll n){
  14. if(n>mx || mp[n]) return;
  15. humble.push_back(n);
  16. mp[n] = true;
  17. for(int i=0;i<4;i++){
  18. gethumble(a[i]*n);
  19. }
  20. }
  21.  
  22. string getst(int n)
  23. {
  24. if(n%10==1 && (n/10)%10!=1) return "st";
  25. else if(n%10==2 && (n/10)%10!=1) return "nd";
  26. else if(n%10==3 && (n/10)%10!=1) return "rd";
  27. else return "th";
  28. }
  29.  
  30. int main()
  31. {
  32. gethumble(1);
  33. sort(humble.begin(),humble.end());
  34. ll n;
  35. while(cin>>n && n){
  36. cout<<"The "<<n<<getst(n)<<" humble number is "<<humble[n-1]<<".\n";
  37. }
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement