結果
| 問題 |
No.1809 Divide NCK
|
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2022-01-27 02:43:28 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 40 ms / 2,000 ms |
| コード長 | 970 bytes |
| コンパイル時間 | 7,327 ms |
| コンパイル使用メモリ | 467,852 KB |
| 最終ジャッジ日時 | 2025-01-27 15:31:48 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
map<Bint,Bint> prime_factor(Bint x){
map<Bint,Bint> res;
for(Bint i=2;i*i<=x;i++){
while(x%i==0){
res[i]++;
x/=i;
}
}
if(x!=1) res[x]++;
return res;
}
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
Bint n,k,m;
cin>>n>>k>>m;
map<Bint,Bint> M=prime_factor(m);
Bint ans=1000000000000000000;
for(auto [a,b]:M){
Bint sum=0;
Bint t=a;
while(n/t>=1){
sum+=n/t;
t*=a;
}
t=a;
while(k/t>=1){
sum-=k/t;
t*=a;
}
t=a;
while((n-k)/t>=1){
sum-=(n-k)/t;
t*=a;
}
ans=min(ans,sum/b);
}
cout<<ans<<endl;
return 0;
}
umezo