結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー Fujisaki_prprFujisaki_prpr
提出日時 2016-08-29 15:45:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 297 ms / 1,000 ms
コード長 1,490 bytes
コンパイル時間 1,766 ms
コンパイル使用メモリ 167,076 KB
実行使用メモリ 81,272 KB
最終ジャッジ日時 2023-08-22 06:19:31
合計ジャッジ時間 13,387 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 289 ms
81,220 KB
testcase_01 AC 297 ms
81,156 KB
testcase_02 AC 296 ms
81,220 KB
testcase_03 AC 280 ms
80,992 KB
testcase_04 AC 279 ms
81,092 KB
testcase_05 AC 276 ms
80,968 KB
testcase_06 AC 284 ms
81,164 KB
testcase_07 AC 284 ms
81,084 KB
testcase_08 AC 282 ms
80,956 KB
testcase_09 AC 290 ms
80,936 KB
testcase_10 AC 289 ms
81,160 KB
testcase_11 AC 288 ms
80,968 KB
testcase_12 AC 287 ms
81,152 KB
testcase_13 AC 281 ms
81,092 KB
testcase_14 AC 281 ms
81,272 KB
testcase_15 AC 281 ms
81,224 KB
testcase_16 AC 294 ms
81,164 KB
testcase_17 AC 276 ms
81,160 KB
testcase_18 AC 276 ms
81,272 KB
testcase_19 AC 283 ms
81,220 KB
testcase_20 AC 293 ms
80,932 KB
testcase_21 AC 280 ms
81,160 KB
testcase_22 AC 290 ms
81,080 KB
testcase_23 AC 285 ms
81,224 KB
testcase_24 AC 285 ms
81,208 KB
testcase_25 AC 278 ms
81,160 KB
testcase_26 AC 291 ms
81,268 KB
testcase_27 AC 287 ms
80,932 KB
testcase_28 AC 284 ms
81,140 KB
testcase_29 AC 286 ms
80,928 KB
testcase_30 AC 280 ms
81,052 KB
testcase_31 AC 287 ms
81,140 KB
testcase_32 AC 292 ms
81,088 KB
testcase_33 AC 295 ms
80,972 KB
testcase_34 AC 290 ms
81,136 KB
testcase_35 AC 284 ms
81,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll PrimeMax = 10000001;
int is_prime[PrimeMax],S = 0;
vector<ll> p(PrimeMax/2);
void Eratosthenes(){
  for(int i = 0; i < PrimeMax; i++){
    is_prime[i] = 1;
  }
  is_prime[0] = 0;
  is_prime[1] = 0;
  for(int i = 2; i < PrimeMax ; i++){
    if(is_prime[i]){
      p[S] = i;
      ++S;
      for(int j = 0; i * (j + 2) < PrimeMax; j++){
        is_prime[i *(j + 2)] = 0;
      }
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  Eratosthenes();
  ll n,l;
  cin >> n >> l;
  ll ans = 0;
  rep(i,S){
    ll s = l - (n-1) * p[i] + 1 ;
    if(s > 0){
      ans += s;
    }
    if(p[i] > l || s < 0) break;
  }
  cout << ans << endl;
  return 0;
}

0