結果

問題 No.1809 Divide NCK
コンテスト
ユーザー nyuminyusupe
提出日時 2024-09-28 04:06:50
言語 C++14
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++14 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 4 ms / 2,000 ms
+ 239µs
コード長 704 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 900 ms
コンパイル使用メモリ 180,336 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-05 12:01:42
合計ジャッジ時間 3,046 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#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