結果

問題 No.847 Divisors of Power
ユーザー ikdikd
提出日時 2019-07-05 22:02:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,084 bytes
コンパイル時間 781 ms
コンパイル使用メモリ 85,336 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-04-16 07:19:55
合計ジャッジ時間 1,869 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 98 ms
8,704 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 24 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 113 ms
9,728 KB
testcase_25 WA -
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <tuple>

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int64_t N, K, M;
vector<pair<int64_t, int64_t>> factors;
set<int64_t> cand;

vector<pair<int64_t, int64_t>> f(int64_t n) {
  vector<pair<int64_t, int64_t>> ret;
  for (int64_t i = 2; i * i <= n; i++) {
    int cnt = 0;
    while (n % i == 0) {
      n /= i;
      cnt += 1;
    }
    if (cnt > 0) {
      ret.emplace_back(i, cnt);
    }
  }
  if (n > 1) {
    ret.emplace_back(n, 1);
  }
  return ret;
}

void dfs(int i, int64_t val) {
  if (val > M or val < 0) return;
  cand.insert(val);
  if (i >= factors.size()) return;
  int64_t p = 1;
  int64_t v, cnt;
  tie(v, cnt) = factors[i];
  dfs(i + 1, val);
  rep(j, cnt) {
    if (val * p * v > M) break;
    dfs(i + 1, val * p * v);
    p *= v;
    if (p * v > M) break;
  }
  dfs(i + 1, val * p);
}

int main() {
  
  cin >> N >> K >> M;

  factors = f(N);
  for (auto &p: factors) {
    p.second *= K;
  }
  dfs(0, 1);
  cout << cand.size() << endl;

  return 0;
}
0