結果
問題 |
No.1809 Divide NCK
|
ユーザー |
👑 ![]() |
提出日時 | 2022-01-14 21:51:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 1,880 bytes |
コンパイル時間 | 1,268 ms |
コンパイル使用メモリ | 81,300 KB |
最終ジャッジ日時 | 2025-01-27 11:19:17 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> using namespace std; using i64 = long long; using u64 = unsigned long long; using i32 = int; using u32 = unsigned int; #define rep(i,n) for(int i=0; i<(n); i++) vector<pair<u64,u64>> factorize(u64 n){ vector<pair<u64,u64>> res; for(u64 i=2; i*i<=n; i++){ if(n%i) continue; res.push_back({i,0}); while(n%i==0){ n/=i; res.back().second++; } } if(n!=1) res.push_back({n,1}); return res; } vector<u64> divs(vector<pair<u64,u64>> F){ vector<u64> res = {1}; for(auto f:F){ int t=res.size() * f.second; rep(i,t) res.push_back(res[i] * f.first); } return move(res); } vector<pair<u64,u64>> gcd_frequency(u64 n){ vector<pair<u64,u64>> ans; ans.push_back(make_pair((u64)1, (u64)1)); for(auto f : factorize(n)){ vector<pair<u64,u64>> buf; u64 multiplier = 1; u64 inv_multiplier = 1; for(u64 p_idx=0; p_idx<f.second; p_idx++) inv_multiplier *= f.first; for(u64 p_idx=0; p_idx<=f.second; p_idx++){ if(p_idx != 0){ multiplier *= f.first; inv_multiplier /= f.first; } u64 freq = inv_multiplier; if(p_idx != f.second) freq = freq / f.first * (f.first - 1); for(auto a : ans) buf.push_back(make_pair(a.first*multiplier, a.second*freq)); } swap(ans, buf); } return ans; } u64 fp(u64 n, u64 p){ u64 ans = 0; while(n){ ans += n / p; n /= p; } return ans; } int main() { u64 N,K,M; cin >> N >> K >> M; auto F = factorize(M); u64 ans = 5001001001001001001; for(auto[ p,e ] : F){ u64 fpres = fp(N,p) - fp(K,p) - fp(N-K,p); fpres /= e; ans = min(ans, fpres); } cout << ans << endl; return 0; } struct ios_do_not_sync{ ios_do_not_sync(){ std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } ios_do_not_sync_instance;