QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#516486#8339. Rooted TreeSunwkingWA 0ms3644kbC++141.8kb2024-08-12 17:23:012024-08-12 17:23:02

Judging History

你现在查看的是最新测评结果

  • [2024-08-12 17:23:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-08-12 17:23:01]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using LL = long long;
using PII = pair<LL , int> ;
using ULL = unsigned long long;

const int N = 3e2 + 10 , M = 6e4 + 10, Mod = 998244353 , P = 131;


void solved() {

    LL n , k;
    cin >> n >> k;


    LL t;
    auto check = [&](int b){
        LL nn = n / t;
        LL sum = 0;
        for(int i = 1 ; i <= k ; i ++ ){
            // (b + t) ^ (k - i) * b ^ (i - 1)
            LL res = 1;
            for(int j = 1 ; j <= (k - i) ; j ++ ){
                if((__int128)res * (b + t) > nn) return 2;
                res *= (b + t);
            }
            LL ans = 1;
            for(int j = 1 ; j <= i - 1 ; j ++ ){
                if((__int128)ans * b > nn) return 2;
                ans *= b;
            }
            if((__int128)ans * res > nn) return 2;
            if((__int128)sum + ans * res > nn) return 2;
            sum += ans * res;
        }
        if(sum == nn) return 1;
        return 0;
    };

    int ans = 0;
    for(t = 1 ; t * t <= n / t ; t ++ ){

        if(n % t) continue;

        if(k == 3){
            LL deta = 9 * t * t - 12 * (t * t - n / t);

            if(deta < 0)
                continue;
            double x1 = (double)(-3 * t + sqrt(deta)) / 6;
            if(x1 > 0 && x1 == (int)x1) ans ++;
            continue;
        }

        int l = 1 , r = 1e6;
        while (l < r){
            int mid = (l + r) >> 1;
            if(check(mid)) r = mid;
            else l = mid + 1;
        }
        if(check(l) == 1) ans ++;
    }

    cout << ans << "\n";
}

int main(){

//      freopen("D:\\dev\\code\\sunwking\\1.in" , "r" , stdin);

    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);


    int t = 1;
    cin >> t;

    while(t -- )
        solved();


    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3644kb

input:

6 2

output:

0
0
0
0
0
0

result:

wrong answer 1st numbers differ - expected: '18', found: '0'