結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー tonyu0
提出日時 2020-05-17 19:44:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 109 ms / 1,000 ms
コード長 579 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 98,168 KB
最終ジャッジ日時 2025-01-10 12:45:29
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

ll n, l;
int main()
{
  cin >> n >> l;
  vector<ll> prime;
  vector<bool> is_prime(10000010, true);
  for (ll i = 2; i < l; ++i)
  {
    if (is_prime[i])
    {
      prime.push_back(i);
      for (ll j = i + i; j < l; j += i)
      {
        is_prime[j] = false;
      }
    }
  }

  ll ans = 0;
  for (int p : prime)
  {
    ll all = p * ~-n;
    if (all <= l)
    {
      ans += l - all + 1;
    }
  }
  cout << ans << endl;
  return 0;
}
0