fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <chrono>
  4. #include <iostream>
  5. #include <algorithm> // for copy
  6. #include <iterator> // for ostream_iterator
  7.  
  8. static std::vector<uint64_t> prime;
  9.  
  10. int main() {
  11. std::cout << "欝だしのう" << std::endl;
  12. int num = 10000;
  13. prime.reserve(num);
  14.  
  15. auto S = std::chrono::system_clock::now();
  16. prime.push_back(2);
  17. int j, k;
  18. for (int i = 3; ;++i) {
  19. int size = prime.size();
  20. if (size >= num)
  21. break;
  22. bool isSosu = true;
  23. for (j = 0; j < size; ++j) {
  24. if (prime[j] * 2 > i)
  25. break;
  26. if (i % prime[j] == 0) {
  27. isSosu = false;
  28. break;
  29. }
  30. }
  31. if (isSosu)
  32. prime.push_back(i);
  33. }
  34.  
  35. auto E = std::chrono::system_clock::now();
  36. auto Eli = std::chrono::duration_cast<std::chrono::milliseconds>(E - S);
  37. std::cout << "経過時間は" << Eli.count() << "ミリ秒だ!" << std::endl;
  38.  
  39. //copy(prime.begin(), prime.end(), std::ostream_iterator<uint64_t>(std::cout, " "));
  40.  
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.65s 3472KB
stdin
Standard input is empty
stdout
欝だしのう
経過時間は651ミリ秒だ!