結果

問題 No.106 素数が嫌い!2
ユーザー maimai
提出日時 2018-01-23 20:27:30
言語 cLay
(20240104-1)
結果
TLE  
実行時間 -
コード長 750 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 166,948 KB
実行使用メモリ 20,128 KB
最終ジャッジ日時 2023-09-18 23:54:22
合計ジャッジ時間 14,866 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

void gen_primelist(vector<int>& out, ll high) {
    out.resize(high + 1);
    out[0] = out[1] = 1;
    ll sqh = (ll)sqrt(high);
    for (ll i = 2; i <= sqh; i++) {
        if (out[i] == 0) {
            for (ll j = i*i; j <= high; j += i) { // i*i
                out[j] = 1;
            }
        }
    }
}

vector<int> isc,pl,memo;

int count(int x) {
    if (memo[x]) return memo[x];
    for (int p:pl){
        if (x%p==0)
            return memo[x]=count(x/p)+1;
        if (x==p)
            break;
    }
    return memo[x]=1;
}

{
    ll N,K;rd(N,K);
    gen_primelist(isc,N+1);
    pl.reserve((ll)sqrt(N));
    REP(i,N+1) if(!isc[i]) pl.push_back(i);
    
    memo.resize(N+1);
    ll cnt=0;
    REP(i,N-1) cnt+=count(N-i)>=K;
    wt(cnt);
}
0