結果

問題 No.407 鴨等素数間隔列の数え上げ
ユーザー tottoripapertottoripaper
提出日時 2016-10-20 21:15:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 134 ms / 1,000 ms
コード長 1,041 bytes
コンパイル時間 2,878 ms
コンパイル使用メモリ 146,300 KB
実行使用メモリ 18,744 KB
最終ジャッジ日時 2023-08-22 06:37:59
合計ジャッジ時間 8,487 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
18,328 KB
testcase_01 AC 117 ms
17,188 KB
testcase_02 AC 105 ms
18,068 KB
testcase_03 AC 110 ms
18,556 KB
testcase_04 AC 102 ms
17,536 KB
testcase_05 AC 102 ms
18,744 KB
testcase_06 AC 108 ms
17,424 KB
testcase_07 AC 114 ms
17,852 KB
testcase_08 AC 114 ms
17,712 KB
testcase_09 AC 105 ms
17,324 KB
testcase_10 AC 105 ms
17,212 KB
testcase_11 AC 125 ms
17,552 KB
testcase_12 AC 111 ms
17,456 KB
testcase_13 AC 106 ms
17,360 KB
testcase_14 AC 120 ms
17,124 KB
testcase_15 AC 120 ms
17,732 KB
testcase_16 AC 112 ms
18,708 KB
testcase_17 AC 119 ms
17,536 KB
testcase_18 AC 110 ms
18,000 KB
testcase_19 AC 107 ms
17,128 KB
testcase_20 AC 118 ms
17,452 KB
testcase_21 AC 108 ms
17,652 KB
testcase_22 AC 129 ms
17,944 KB
testcase_23 AC 131 ms
17,216 KB
testcase_24 AC 122 ms
17,764 KB
testcase_25 AC 105 ms
17,248 KB
testcase_26 AC 109 ms
17,272 KB
testcase_27 AC 113 ms
17,356 KB
testcase_28 AC 114 ms
17,240 KB
testcase_29 AC 107 ms
17,032 KB
testcase_30 AC 108 ms
17,600 KB
testcase_31 AC 108 ms
17,504 KB
testcase_32 AC 134 ms
17,396 KB
testcase_33 AC 106 ms
17,820 KB
testcase_34 AC 110 ms
17,936 KB
testcase_35 AC 119 ms
17,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

bool isNotPrime[10000000];
vector<int> primes;

int main(){
    //*
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    /*/
      /*/

    primes.emplace_back(2);
    for(int i=4;i<10000000;i+=2){
        isNotPrime[i] = true;
    }

    for(int i=3;i<10000000;i+=2){
        if(!isNotPrime[i]){
            primes.emplace_back(i);
            for(int j=i*2;j<10000000;j+=i){
                isNotPrime[j] = true;
            }
        }
    }
    
    int N, L;
    std::cin >> N >> L;
    
    ll res = 0ll;
    for(int p : primes){
        int a = L / p + 1, b = L % p + 1;
        
        if(a >= N){
            res += 1ll * b * (a - N + 1);
            res += 1ll * (p - b) * (a - N);
        }
    }

    std::cout << res << std::endl;
}
0