結果

問題 No.1809 Divide NCK
ユーザー ytftytft
提出日時 2022-02-12 23:06:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 13 ms / 2,000 ms
コード長 631 bytes
コンパイル時間 1,672 ms
コンパイル使用メモリ 173,328 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-29 02:22:18
合計ジャッジ時間 3,030 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int count(long long a,long long b){
    long long temp=1;
    int ret=0;
    while(a/b>=temp){
        temp*=b;
        ret+=a/temp;
    }
    return ret;
}

int main(){
    long long N,K,M;
    int ans=INT_MAX,temp;
    cin>>N>>K>>M;
    map<long long,int> p;
    for(long long i=2;i*i<=M;++i){
        while(M%i==0){
            ++p[i];
            M/=i;
        }
    }
    if(M>1){
        ++p[M];
    }
    for(auto i=p.begin();i!=p.end();++i){
        temp=count(N,i->first)-count(K,i->first)-count(N-K,i->first);
        ans=min(ans,temp/i->second);
    }
    cout<<ans<<endl;
}
0