結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー nenuon
提出日時 2017-07-04 22:03:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 55 ms / 1,000 ms
コード長 934 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 88,888 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-10-05 16:13:58
合計ジャッジ時間 3,334 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 * i < MAX + 1; i++){
    if(isPrime[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(d, 2, MAX){
    if(d * (N - 1) > L) break;
    if(!isPrime[d]) continue;
    if(d * (N - 1) <= L) ans += (L - (d * (N - 1))) + 1;
  }
  cout << ans << endl;
  return 0;
}
0