fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int nthUglyNumber(int n) {
  4. priority_queue<int, vector<int>, greater<int>> p;
  5. p.push(1);
  6. int t,c=1;;
  7. while(c<n)
  8. {
  9. while(t==p.top())
  10. p.pop();
  11. t=p.top();
  12. p.pop();
  13. c++;
  14. p.push(t*2);
  15. p.push(t*3);
  16. p.push(t*5);
  17. }
  18. return t;
  19. }
  20. int main()
  21. {
  22. cout<<nthUglyNumber(10);
  23.  
  24. }
Success #stdin #stdout 0s 4396KB
stdin
Standard input is empty
stdout
10