結果

問題 No.847 Divisors of Power
ユーザー kimiyuki
提出日時 2019-07-05 22:59:06
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 2,634 bytes
コンパイル時間 2,275 ms
コンパイル使用メモリ 205,892 KB
最終ジャッジ日時 2025-01-07 06:06:18
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 24 TLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;
/**
* @note O(\sqrt{n})
* @note about 1.0 sec for 10^5 queries with n < 10^10
*/
struct prepared_primes {
int size;
vector<int> sieve;
vector<int> primes;
prepared_primes(int size_)
: size(size_) {
sieve.resize(size);
REP3 (p, 2, size) if (sieve[p] == 0) {
primes.push_back(p);
for (int k = p; k < size; k += p) {
if (sieve[k] == 0) {
sieve[k] = p;
}
}
}
}
vector<ll> prime_factorize(ll n) {
assert (1 <= n and n < (ll)size * size);
vector<ll> result;
// trial division for large part
for (int p : primes) {
if (n < size or n < (ll)p * p) {
break;
}
while (n % p == 0) {
n /= p;
result.push_back(p);
}
}
// small part
if (n == 1) {
// nop
} else if (n < size) {
while (n != 1) {
result.push_back(sieve[n]);
n /= sieve[n];
}
} else {
result.push_back(n);
}
assert (is_sorted(ALL(result)));
return result;
}
vector<ll> list_all_factors(ll n) {
auto p = prime_factorize(n);
vector<ll> d;
d.push_back(1);
for (int l = 0; l < p.size(); ) {
int r = l + 1;
while (r < p.size() and p[r] == p[l]) ++ r;
int n = d.size();
REP (k1, r - l) {
REP (k2, n) {
d.push_back(d[d.size() - n] * p[l]);
}
}
l = r;
}
return d;
}
};
int solve(int n, int k, int m) {
prepared_primes primes(sqrt(n) + 100);
auto factors = primes.list_all_factors(n);
unordered_set<int> cur, prv;
cur.insert(1);
while (k -- and cur.size() != prv.size()) {
cur.swap(prv);
cur.clear();
for (int d1 : prv) for (int d2 : factors) {
if ((ll)d1 * d2 <= m) {
cur.insert(d1 * d2);
}
}
}
return cur.size();
}
int main() {
int n, k, m; cin >> n >> k >> m;
cout << solve(n, k, m) << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0