結果

問題 No.473 和と積の和
ユーザー ctyl_0ctyl_0
提出日時 2016-11-17 17:14:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 576 ms / 3,000 ms
コード長 2,245 bytes
コンパイル時間 1,545 ms
コンパイル使用メモリ 115,096 KB
実行使用メモリ 299,840 KB
最終ジャッジ日時 2023-08-22 07:58:48
合計ジャッジ時間 6,452 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 191 ms
135,032 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 4 ms
5,620 KB
testcase_24 AC 6 ms
6,548 KB
testcase_25 AC 576 ms
299,840 KB
testcase_26 AC 145 ms
108,404 KB
testcase_27 AC 175 ms
125,876 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 323 ms
149,920 KB
testcase_35 AC 322 ms
150,084 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 312 ms
150,004 KB
testcase_39 AC 161 ms
70,576 KB
testcase_40 AC 165 ms
70,556 KB
testcase_41 AC 71 ms
70,548 KB
testcase_42 AC 274 ms
272,312 KB
testcase_43 AC 280 ms
272,284 KB
testcase_44 AC 309 ms
272,244 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#include <cassert>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

vector<ll> D;
map<ll, int> M;
vector<vector<vector<int>>> dp;

// D[n]をD[m]以上のk個の約数に分解する方法
int dec(int n, int m, int k){
    if(k >= 32) return 0;
//    cout << D[n] << ", " << D[m] << ", " << k << endl;
    if(dp[n][m][k] >= 0) return dp[n][m][k];
    if(k == 0){
        if(D[n] == 1) return dp[n][m][k] = 1;
        else dp[n][m][k] = 0;
    }
    if(k == 1){
        if(n >= m) return dp[n][m][k] = 1;
        else dp[n][m][k] = 0;
    }
    int ret = 0;
    for(int i = m; D[i] * D[i] <= D[n]; i++){
        if(D[n] % D[i] == 0){
            ll a = D[n];
            int cnt = 1;
            while(a % D[i] == 0 && k >= cnt){
                a /= D[i];
                ret += dec(M[a], i + 1, k - cnt);
                cnt++;
            }
        }
    }
    return dp[n][m][k] = ret;
}


vector<ll> divisors(ll n){
    vector<ll> ret;
    for(ll d = 1; d * d <= n; d++){
        if(n % d == 0){
            ret.pb(d);
            if(d * d != n) ret.pb(n / d);
        }
    }
    sort(all(ret));
    rep(i, ret.size()){
        M[ret[i]] = i;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N;
    ll X;
    cin >> N >> X;
    assert(2 <= N && N <= 100);
    assert(1 <= X && X <= 1e9);
    D = divisors(X + 1);
    dp.assign(D.size(), vector<vector<int>>(D.size(), vector<int>(32, -1)));
    
    
    output(dec((int)D.size() - 1, 1, N));
    
    return 0;
}
0