結果

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

ソースコード

diff #

#include <iostream>
#include <set>
#include <stack>
#include <algorithm>
#include <utility>

using namespace std;

typedef long long int ll;
typedef pair<ll, int> Pli;

set<ll> getDivisorSet(ll n) {
  set<ll> divisor;
  ll k = 1;
  while (k * k <= n) {
    if (n % k == 0) {
      divisor.insert(k);
      divisor.insert(n / k);
    }
    k++;
  }
  return divisor;
}

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

  set<ll> divisor = getDivisorSet(N);
  set<ll> powerDivisor;
  stack<Pli> st;
  for (ll x : divisor) st.push(Pli(x, K));
  while (!st.empty()) {
    Pli now = st.top();
    st.pop();
    if (now.second <= 0) continue;
    if (now.first > M) continue;
    auto it = powerDivisor.find(now.first);
    if (it != powerDivisor.end()) continue;
    powerDivisor.insert(now.first);
    for (ll x : divisor) st.push(Pli(now.first * x, now.second - 1));
  }
  int ans = powerDivisor.size();
  cout << ans << endl;
  return 0;
}
0