結果
| 問題 |
No.847 Divisors of Power
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-08-05 22:50:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 2,226 bytes |
| コンパイル時間 | 869 ms |
| コンパイル使用メモリ | 75,888 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-07 03:02:20 |
| 合計ジャッジ時間 | 1,765 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
ソースコード
#include <iostream>
#include <vector>
#include <utility>
using namespace std;
using ll = long long int;
#define INSERTIVE_ENVIRONMENT
/*
* Eratosthenes' sieve; prime factorization
*/
#ifndef INSERTIVE_ENVIRONMENT
#include <vector>
#include <utility>
#endif
const unsigned int MAX_PRIME = 100000;
bool is_prime[MAX_PRIME+1];
std::vector<unsigned int> prime;
void build_sieve () {
// initialize
for (unsigned int x = 0; x <= MAX_PRIME; x++)
is_prime[x] = 1;
// special treatment for 2
is_prime[0] = 0;
is_prime[1] = 0;
prime.push_back(2);
for (unsigned int x = 4; x <= MAX_PRIME; x += 2) {
is_prime[x] = 0;
}
for (unsigned int p = 3; p <= MAX_PRIME; p += 2) {
if (is_prime[p] == 1) {
prime.push_back(p);
for (unsigned int x = 2*p; x <= MAX_PRIME; x += p) {
is_prime[x] = 0;
}
}
}
}
std::vector<std::pair<long long, long long> > factorize (long long x) {
std::vector<std::pair<long long, long long> > res;
for (auto p : prime) {
if (x % p == 0) {
std::pair<long long, long long> node = std::make_pair(p, 0);
while (x % p == 0) {
x = x / p;
node.second++;
}
res.push_back(node);
}
}
if (x != 1)
res.push_back(std::make_pair(x, 1));
return res;
}
template <class T> std::ostream& operator<<(std::ostream& o, const std::vector<T>& v) {
o << "{";
for (int i = 0; i < (int) v.size(); i++)
o << (i > 0 ? ", " : "" ) << v[i];
o << "}";
return o;
}
template <class X, class Y> std::ostream& operator<<(std::ostream& o, const std::pair<X, Y>& p) {
o << "(" << p.first << ", " << p.second << ")";
return o;
}
int n, k, m;
int ans = 0;
std::vector<std::pair<ll, ll> > factors;
void dfs (ll pos, ll product) {
if (pos == factors.size()) {
ans++;
return;
}
std::pair<ll, ll> node = factors[pos];
ll d = product;
for (ll j = 0; j <= node.second; j++) {
if (d > m) break;
dfs(pos + 1, d);
d *= node.first;
}
}
int main() {
build_sieve();
std::cin >> n >> k >> m;
factors = factorize(n);
for (int i = 0; i < factors.size(); i++) {
factors[i].second *= k;
}
dfs(0, 1);
// std::cout << factors << std::endl;
std::cout << ans << std::endl;
return 0;
}