結果

問題 No.1809 Divide NCK
ユーザー nyuminyusupe
提出日時 2024-09-28 04:06:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 1,456 ms
コンパイル使用メモリ 166,224 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-28 04:06:53
合計ジャッジ時間 2,805 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i< (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 998244353;
const int inf = (1<<30);
const ll INF = (1ull<<62);

ll f(ll n,ll k){//k ha sosuu
    ll ans = 0;
    while(n > 0){
        ans += n/k;
        n /= k;
    }
    return ans;
}


int main(){
    ll n,k,m; cin>>n>>k>>m;
    ll t = n-k;
    ll ans = inf;
    for(ll i = 2; i*i <= m; i++){
        if(m%i != 0) continue;
        int c = 0;
        while(m%i == 0){
            m/=i;
            c++;
        }
        ans = min(ans,(f(n,i) - f(k,i) - f(t,i))/c);
    }
    if(m>1) ans = min(ans,(f(n,m) - f(k,m) - f(t,m)));
    cout<<ans<<endl;
}
0