結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,856 KB
testcase_01 AC 3 ms
6,008 KB
testcase_02 AC 4 ms
5,844 KB
testcase_03 AC 350 ms
58,424 KB
testcase_04 AC 4 ms
5,856 KB
testcase_05 AC 3 ms
5,948 KB
testcase_06 AC 4 ms
6,144 KB
testcase_07 AC 4 ms
5,888 KB
testcase_08 AC 4 ms
6,148 KB
testcase_09 AC 3 ms
5,884 KB
testcase_10 AC 3 ms
5,932 KB
testcase_11 AC 4 ms
5,844 KB
testcase_12 AC 3 ms
5,876 KB
testcase_13 AC 4 ms
5,900 KB
testcase_14 AC 4 ms
5,880 KB
testcase_15 AC 4 ms
5,944 KB
testcase_16 AC 4 ms
5,936 KB
testcase_17 AC 4 ms
6,044 KB
testcase_18 AC 4 ms
5,852 KB
testcase_19 AC 4 ms
5,912 KB
testcase_20 AC 3 ms
6,136 KB
testcase_21 AC 3 ms
5,916 KB
testcase_22 AC 4 ms
5,884 KB
testcase_23 AC 7 ms
6,628 KB
testcase_24 AC 9 ms
7,180 KB
testcase_25 AC 1,757 ms
204,392 KB
testcase_26 AC 269 ms
47,328 KB
testcase_27 AC 466 ms
71,704 KB
testcase_28 AC 3 ms
6,004 KB
testcase_29 AC 4 ms
5,972 KB
testcase_30 AC 4 ms
5,924 KB
testcase_31 AC 4 ms
5,956 KB
testcase_32 AC 5 ms
5,940 KB
testcase_33 AC 4 ms
6,164 KB
testcase_34 AC 860 ms
115,356 KB
testcase_35 AC 796 ms
108,860 KB
testcase_36 AC 4 ms
6,012 KB
testcase_37 AC 4 ms
5,924 KB
testcase_38 AC 740 ms
102,496 KB
testcase_39 AC 289 ms
50,096 KB
testcase_40 AC 316 ms
53,992 KB
testcase_41 AC 3 ms
5,884 KB
testcase_42 AC 4 ms
6,292 KB
testcase_43 AC 103 ms
23,800 KB
testcase_44 AC 308 ms
53,064 KB
testcase_45 AC 3 ms
5,952 KB
testcase_46 AC 4 ms
5,892 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){
  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