結果
問題 | No.1383 Numbers of Product |
ユーザー |
![]() |
提出日時 | 2021-07-01 22:54:43 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,614 ms / 2,000 ms |
コード長 | 2,399 bytes |
コンパイル時間 | 4,500 ms |
コンパイル使用メモリ | 155,904 KB |
最終ジャッジ日時 | 2025-01-22 15:28:52 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 51 |
ソースコード
#include <iostream>#include <algorithm>#include <iomanip>#include <vector>#include <queue>#include <set>#include <map>#include <tuple>#include <cmath>#include <numeric>#include <functional>#include <cassert>#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }using namespace std;typedef long long ll;const ll INF = 2e18;ll calc(ll a, ll b, ll k){ll ans = a;for(ll i = 1; i <= b; i++){if(k >= INF/i) return INF;ll x = a+k*i;if(ans >= INF/x) return INF;ans *= x;}// cout << "calc(" << a << "," << b << "," << k << ") = " << ans << endl;return ans;}ll f(ll x, ll k){ll l = 0, r = 1e9;while(r-l > 1){ll c = (l+r)/2;if(calc(c, 1, k) > x) r = c;else l = c;}return l;}int naive(ll n, ll k, ll m){map<ll, int> cnt;for(int b = 1; ; b++){if(calc(1, b, k) > n) break;for(int a = 1; ; a++){ll x = calc(a, b, k);if(x > n) break;if(cnt.count(x) == 0) cnt[x] = 1;else cnt[x]++;}}int ans = 0;for(auto [_, c]: cnt){if(c == m) ans++;}return ans;}int main(){ios::sync_with_stdio(false);cin.tie(0);cout << setprecision(10) << fixed;ll n, k, m; cin >> n >> k >> m;map<ll, int> cnt;for(int b = 2; ; b++){if(calc(1, b, k) > n) break;for(int a = 1; ; a++){ll x = calc(a, b, k);if(x > n) break;if(cnt.count(x) == 0) cnt[x] = 1;else cnt[x]++;}}vector<ll> v;for(auto &[x, c]: cnt) {ll y = f(x, k);if(calc(y, 1, k) == x){v.push_back(x);c++;}}int ans = 0;for(auto [_, c]: cnt){if(c == m) ans++;}if(m == 1){ll y = f(n, k);ans += y;for(auto [x, c]: cnt){ll y = f(x, k);if(calc(y, 1, k) == x) ans--;}}cout << ans << endl;// cout << naive(n, k, m) << endl;}