結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー saltcandy123
提出日時 2016-08-05 22:46:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 78 ms / 1,000 ms
コード長 523 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 61,948 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-15 20:54:16
合計ジャッジ時間 2,542 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <utility>
#include <vector>

int main() {
  long long n, l;
  std::vector<bool> is_prime(10000001, true);
  long long count = 0;
  std::cin >> n >> l;
  is_prime[0] = is_prime[1] = false;
  for (int p = 2; p <= l; ++p) {
    if (is_prime[p]) {
      for (int k = 2; k * p <= l; ++k) {
        is_prime[k * p] = false;
      }
      count += std::max(0LL, l - (n - 1) * p + 1);
    }
  }
  std::cout << count << std::endl;
  return 0;
}
0