結果

問題 No.1657 Sum is Prime (Easy Version)
ユーザー mmn15277198mmn15277198
提出日時 2021-08-28 14:16:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 905 ms
コンパイル使用メモリ 94,708 KB
実行使用メモリ 11,820 KB
最終ジャッジ日時 2024-05-01 15:51:57
合計ジャッジ時間 3,723 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
11,820 KB
testcase_01 AC 79 ms
11,776 KB
testcase_02 AC 79 ms
11,776 KB
testcase_03 AC 79 ms
11,776 KB
testcase_04 AC 84 ms
11,776 KB
testcase_05 AC 81 ms
11,776 KB
testcase_06 AC 78 ms
11,776 KB
testcase_07 AC 78 ms
11,776 KB
testcase_08 AC 79 ms
11,632 KB
testcase_09 AC 78 ms
11,648 KB
testcase_10 AC 77 ms
11,648 KB
testcase_11 AC 80 ms
11,700 KB
testcase_12 AC 80 ms
11,696 KB
testcase_13 AC 80 ms
11,640 KB
testcase_14 AC 83 ms
11,776 KB
testcase_15 AC 84 ms
11,708 KB
testcase_16 AC 80 ms
11,776 KB
testcase_17 AC 79 ms
11,776 KB
testcase_18 AC 78 ms
11,776 KB
testcase_19 AC 77 ms
11,632 KB
testcase_20 AC 80 ms
11,648 KB
testcase_21 AC 81 ms
11,776 KB
testcase_22 AC 81 ms
11,776 KB
testcase_23 AC 81 ms
11,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //cout << fixed << setprecision(15);
  
  int l , r;
  cin >> l >> r;
  vector<int> prime(2200000 , 0);
  prime[1] = 2;
  for (int i = 2; i <= 2000000; i++) {
    for (int j = i; j <= 2000000; j += i) {
      prime[j]++;
    }
  }
  long long ans = 0;
  for (int i = l; i <= r; i++) {
    if (prime[i] <= 1) ans++;
  }
  for (int i = l; i <= r - 1; i++) {
    if (prime[i + i + 1] <= 1) ans++;
  }
  cout << ans << endl;
  return 0;
}
0