結果

問題 No.473 和と積の和
ユーザー imulanimulan
提出日時 2017-05-17 11:58:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,224 ms / 3,000 ms
コード長 1,203 bytes
コンパイル時間 1,897 ms
コンパイル使用メモリ 181,412 KB
実行使用メモリ 96,472 KB
最終ジャッジ日時 2023-10-17 14:43:00
合計ジャッジ時間 8,949 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 307 ms
36,920 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 4 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 136 ms
19,608 KB
testcase_26 AC 217 ms
28,140 KB
testcase_27 AC 94 ms
15,368 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 19 ms
6,248 KB
testcase_35 AC 86 ms
14,844 KB
testcase_36 AC 2 ms
4,348 KB
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 161 ms
22,152 KB
testcase_39 AC 100 ms
15,296 KB
testcase_40 AC 73 ms
12,260 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 1,006 ms
72,892 KB
testcase_43 AC 1,224 ms
95,244 KB
testcase_44 AC 1,193 ms
96,472 KB
testcase_45 AC 2 ms
4,348 KB
testcase_46 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

using pi = pair<int,int>;
using P = pair<pi,int>;

int n;
ll x;

int D;
vector<int> d;

void factor()
{
    int X=x+1;
    d.pb(X);
    for(int i=2; i*i<=X; ++i)
    {
        if(X%i==0)
        {
            d.pb(i);
            d.pb(X/i);
        }
    }
    sort(all(d));
    d.erase(unique(all(d)),d.end());

    D = d.size();
}

map<P,int> dp;
int f(int rem, int didx, int val)
{
    if(didx==D) return (rem==0 && val==1);
    if(d[didx]>val)
    {
        if(rem==0) return (val==1);
        return 0;
    }

    ll min_val=1;
    rep(i,rem)
    {
        min_val*=d[didx];
        if(min_val>val) return 0;
    }

    P p = P(pi(rem,didx),val);
    if(dp.count(p)) return dp[p];

    int ret=0;
    ll div=1;
    for(int i=0; i<=rem; ++i)
    {
        if(val%div==0) ret += f(rem-i, didx+1, val/div);
        else break;

        div *= d[didx];
    }

    dp[p] = ret;
    return ret;
}

int main()
{
    cin >>n >>x;
    factor();

    cout << f(n,0,x+1) << endl;
    return 0;
}
0