結果

問題 No.847 Divisors of Power
ユーザー batsumarubatsumaru
提出日時 2019-07-05 22:51:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,239 bytes
コンパイル時間 1,725 ms
コンパイル使用メモリ 179,256 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-06 22:45:33
合計ジャッジ時間 2,693 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
map<ll, ll> mp;
ll ans = 0;
ll n, k, m;

void dec_prime(ll n){
  ll a = 2;
  while(n > 1){
    if(a*a > n){
      mp[n]++;
      break;
    }
    if(n%a == 0){
      while(n%a == 0){
        mp[a]++;
        n /= a;
      }
      a = 2;
    }else{
      a++;
    }
  }
}

bool dfs(ll t, ll pos, vector<vector<ll>>& p){
  if(t > m) return false;
  if(pos == p.size()){
    ans++;
    return true;
  }
  ll cur = t;
  REP(i, p[pos][1]+1){
    bool b = dfs(cur, pos+1, p);
    if(!b) break;
    cur *= p[pos][0];
  }
  return true;
}


int main() {
  cin >> n >> k >> m;
  if(n==1){
    cout << 1 << endl;
    return 0;
  }
  dec_prime(n);
  vector<vector<ll>> p;
  if(mp.size() == 0){
    p.push_back({n, k});
  }
  FOREACH(x,mp){
    p.push_back({x.first, x.second * k});
  }

  dfs(1, 0, p);
  cout << ans << endl;
}
0