結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー nenuon
提出日時 2017-07-04 21:57:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 84 ms / 1,000 ms
コード長 931 bytes
コンパイル時間 653 ms
コンパイル使用メモリ 92,532 KB
実行使用メモリ 21,492 KB
最終ジャッジ日時 2024-10-05 16:11:16
合計ジャッジ時間 4,554 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

const ll MAX = 10000000;
bool isPrime[MAX];
vector<ll> prime;
void makePrime(){
  for (ll i = 0; i < MAX; i++){
    isPrime[i] = true;
  }
  for (ll i = 2; i < MAX; i++){
    if(isPrime[i]){
      prime.push_back(i);
      for (ll j = 2 * i; j < MAX; j += i) {
        isPrime[j] = false;
      }
    }
  }
  return;
}
int main(){
  ll N, L;
  cin >> N >> L;
  // L / (N - 1) 以下の素数の個数
  makePrime();
  ll ans = 0;
  FOR(i, 0, prime.size()){
    if(prime[i] * (N - 1) <= L) ans += (L - (prime[i] * (N - 1))) + 1;
    else break;
  }
  cout << ans << endl;
  return 0;
}
0