結果

問題 No.473 和と積の和
ユーザー @abcde@abcde
提出日時 2019-05-10 23:53:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 62 ms / 3,000 ms
コード長 1,498 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 172,456 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-14 18:02:12
合計ジャッジ時間 4,314 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 30 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 32 ms
4,380 KB
testcase_26 AC 20 ms
4,376 KB
testcase_27 AC 16 ms
4,384 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 10 ms
4,376 KB
testcase_35 AC 38 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 62 ms
4,376 KB
testcase_39 AC 51 ms
4,380 KB
testcase_40 AC 36 ms
4,380 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 3 ms
4,380 KB
testcase_44 AC 12 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// TLE版を修正.
// 自力解答不可(※計算量削減が分からない)のため, 正解者様のソースを参照.
// https://yukicoder.me/submissions/139856
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

double EPS = 0.0000000000001;
vector<LL> D;

// nをD[m]以上のk個の約数で分解する方法
LL dec(LL n, LL m, int k){
    
    if(k == 0){
        if(n == 1) return 1;
        else return 0;
    }
    if(k == 1){
        if(n >= D[m]) return 1;
        else return 0;
    }
    if(pow(n, 1.0 / k) + EPS < D[m]) return 0;
    
    LL ret = 0;
    for(int d = m; d < D.size(); d++){
        if(n < D[d] * D[d]) break;
        if(n % D[d] == 0){
            LL nn = n;
            int cnt = 1;
            while(nn % D[d] == 0 && k >= cnt){
                nn /= D[d];
                ret += dec(nn, d + 1, k - cnt);
                cnt++;
            }
        }
    }
    return ret;
}

vector<LL> div(LL n){
    vector<LL> ret;
    for(LL d = 2; d * d <= n; d++) {
        if(n % d == 0) {
            ret.push_back(d);
            if(d * d != n) ret.push_back(n / d);
        }
    }
    ret.push_back(n);
    sort(ret.begin(), ret.end());
    return ret;
}

int main() {
    
    // 1. 入力情報取得.
    LL N, X;
    // cin >> N >> X;
    scanf("%llu %llu", &N, &X);
    
    // 2. X + 1 を 素因数分解.
    D = div(X + 1);
    
    // 3. 出力 ~ 後処理.
    LL ans = dec(X + 1, 0, N);
    printf("%llu\n", ans);
    return 0;
    
}
0