結果

問題 No.473 和と積の和
ユーザー koba-e964koba-e964
提出日時 2016-12-23 03:21:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,854 ms / 3,000 ms
コード長 1,196 bytes
コンパイル時間 930 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 204,456 KB
最終ジャッジ日時 2023-08-22 08:41:41
合計ジャッジ時間 9,461 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,020 KB
testcase_01 AC 4 ms
5,956 KB
testcase_02 AC 4 ms
5,920 KB
testcase_03 AC 390 ms
58,456 KB
testcase_04 AC 4 ms
5,924 KB
testcase_05 AC 4 ms
5,928 KB
testcase_06 AC 4 ms
5,964 KB
testcase_07 AC 4 ms
5,916 KB
testcase_08 AC 4 ms
5,916 KB
testcase_09 AC 4 ms
5,920 KB
testcase_10 AC 4 ms
5,912 KB
testcase_11 AC 4 ms
5,988 KB
testcase_12 AC 4 ms
5,932 KB
testcase_13 AC 4 ms
5,972 KB
testcase_14 AC 4 ms
5,928 KB
testcase_15 AC 4 ms
5,936 KB
testcase_16 AC 4 ms
5,984 KB
testcase_17 AC 4 ms
5,968 KB
testcase_18 AC 4 ms
5,904 KB
testcase_19 AC 4 ms
5,916 KB
testcase_20 AC 3 ms
5,952 KB
testcase_21 AC 3 ms
6,016 KB
testcase_22 AC 4 ms
6,096 KB
testcase_23 AC 7 ms
6,608 KB
testcase_24 AC 10 ms
7,312 KB
testcase_25 AC 1,854 ms
204,456 KB
testcase_26 AC 291 ms
47,460 KB
testcase_27 AC 514 ms
71,704 KB
testcase_28 AC 4 ms
5,904 KB
testcase_29 AC 4 ms
6,024 KB
testcase_30 AC 4 ms
6,032 KB
testcase_31 AC 4 ms
6,000 KB
testcase_32 AC 4 ms
5,984 KB
testcase_33 AC 3 ms
5,956 KB
testcase_34 AC 934 ms
115,228 KB
testcase_35 AC 865 ms
108,872 KB
testcase_36 AC 5 ms
6,128 KB
testcase_37 AC 4 ms
5,988 KB
testcase_38 AC 800 ms
102,480 KB
testcase_39 AC 317 ms
50,124 KB
testcase_40 AC 341 ms
53,968 KB
testcase_41 AC 4 ms
5,924 KB
testcase_42 AC 4 ms
6,240 KB
testcase_43 AC 115 ms
23,832 KB
testcase_44 AC 349 ms
53,064 KB
testcase_45 AC 4 ms
5,932 KB
testcase_46 AC 4 ms
6,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;

const int F = 1500;
const int N = 31;
unordered_map<int, ll> memo[F][N];

ll solve(const VI &fact, int k, int rem, int x) {
  if (x == 1) {
    return rem <= 0 ? 1 : 0;
  }
  if (k >= fact.size()) {
    return 0;
  }
  if (x < fact[k]) {
    return 0;
  }
  if (rem <= 0) {
    return 0;
  }
  ll f = fact[k];
  if (rem == 1) {
    return x >= f ? 1 : 0;
  }
  if (memo[k][rem].count(x)) {
    return memo[k][rem][x];
  }
  ll ret = 0;
  if (x % f == 0) {
    ret += solve(fact, k, rem - 1, x / f);
  }
  ret += solve(fact, k + 1, rem, x);
  return memo[k][rem][x] = ret;
}

int main(void){
  ios::sync_with_stdio(false);
  int n;
  int x;
  cin >> n >> x;
  x += 1;
  if (n >= 30) {
    cout << 0 << endl;
    return 0;
  }
  VI fact;
  for (int i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      if (i > 1) {
	fact.push_back(i);
      }
      if (x != i * i) {
	fact.push_back(x / i);
      }
    }
  }
  sort(fact.begin(), fact.end());
  cout << solve(fact, 0, n, x) << endl;
}
0