結果
問題 |
No.473 和と積の和
|
ユーザー |
|
提出日時 | 2016-12-23 03:21:42 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1,568 ms / 3,000 ms |
コード長 | 1,196 bytes |
コンパイル時間 | 1,079 ms |
コンパイル使用メモリ | 79,712 KB |
実行使用メモリ | 204,544 KB |
最終ジャッジ日時 | 2024-12-16 04:16:36 |
合計ジャッジ時間 | 7,813 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 43 |
ソースコード
#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; }