fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <cstdint>
  4. #include <algorithm>
  5. #include <numeric>
  6. typedef std::vector<std::uint64_t> DType;
  7.  
  8. std::uint64_t MakeHoge(std::uint64_t N){
  9. std::uint64_t i = 1;
  10. DType D;
  11. while (3 * i < N || 5 * i < N){
  12.  
  13. if (3 * i < N) D.push_back(3 * i);
  14. if (5 * i < N) D.push_back(5 * i);
  15. i++;
  16. }
  17.  
  18. std::sort(D.begin(), D.end());
  19. D.erase(std::unique(D.begin(), D.end()), D.end());
  20. i = 1;
  21.  
  22. while (9*i<N){
  23. auto it = std::lower_bound(D.begin(), D.end(), 9 * i);
  24. if(*it == 9*i) it = D.erase(it);
  25. i++;
  26. }
  27.  
  28. return std::accumulate(D.begin(), D.end(), 0llu);
  29. }
  30.  
  31. int main(){
  32. std::uint64_t N;
  33.  
  34. N = MakeHoge(300000);
  35. std::cout << N << std::endl;
  36.  
  37. return 0;
  38.  
  39. }
Success #stdin #stdout 4.41s 3232KB
stdin
Standard input is empty
stdout
15999800001