結果

問題 No.473 和と積の和
ユーザー 🍡yurahuna🍡yurahuna
提出日時 2016-12-19 22:50:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 447 ms / 3,000 ms
コード長 2,278 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 180,608 KB
実行使用メモリ 19,232 KB
最終ジャッジ日時 2023-08-22 08:00:58
合計ジャッジ時間 5,787 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 73 ms
7,212 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 447 ms
19,232 KB
testcase_26 AC 51 ms
6,416 KB
testcase_27 AC 93 ms
8,596 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 3 ms
4,384 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 337 ms
15,668 KB
testcase_35 AC 327 ms
14,728 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 302 ms
13,900 KB
testcase_39 AC 181 ms
10,112 KB
testcase_40 AC 201 ms
10,712 KB
testcase_41 AC 226 ms
11,960 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 3 ms
4,384 KB
testcase_44 AC 19 ms
4,816 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

using State = tuple<int, int, int>;
map<State, int> dp;
vi divisors;

// nの2以上sqrt(n)以下の約数を列挙
void setDivisor(int n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            divisors.emplace_back(i);
            // if (i != n / i) res.emplace_back(n / i);
        }
    }
    sort(all(divisors));
}

// y以上の整数n個からなる集合で、すべての要素の積がxとなるものの個数
int dfs(int n, int x, int y) {
    // output(n, x, y);
    if (x < y) return 0;
    if (n == 1) return 1;
    State s(n, x, y);
    if (dp.count(s)) return dp[s];
    int &ret = dp[s];
    for (int i = 0; i < divisors.size(); ++i) {
        int p = divisors[i];
        if (p * p > x) break;
        if (p < y || x % p != 0) continue;
        ret += dfs(n - 1, x / p, p);
    }
    return ret;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int n, x;
    cin >> n >> x;
    setDivisor(x + 1);
    cout << dfs(n, x + 1, 2) << endl;
}
0