結果

問題 No.106 素数が嫌い!2
ユーザー mai
提出日時 2018-01-23 20:28:26
言語 cLay
(20241019-1)
結果
TLE  
実行時間 -
コード長 781 bytes
コンパイル時間 2,271 ms
コンパイル使用メモリ 177,216 KB
実行使用メモリ 16,524 KB
最終ジャッジ日時 2024-07-05 12:56:17
合計ジャッジ時間 14,738 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other TLE * 1 -- * 12
権限があれば一括ダウンロードができます

ソースコード

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);
    memo[0]=memo[1]=memo[2]=1;
    ll cnt=0;
    REP(i,N-1) cnt+=count(N-i)>=K;
    wt(cnt);
}
0