QOJ.ac

QOJ

ID提交记录ID题目HackerOwner结果提交时间测评时间
#610#404667#8336. Indeterminate EquationzhangmingzuzhangmingzuSuccess!2024-05-04 13:35:262024-05-04 13:35:27

详细

Extra Test:

Wrong Answer
time: 43ms
memory: 3860kb

input:

1
16 4

output:

1

result:

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

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#404667#8336. Indeterminate EquationzhangmingzuWA 189ms4100kbC++141.3kb2024-05-04 13:33:582024-10-13 18:53:07

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
__int128 ksm(__int128 x, int y)
{
    __int128 ans = 1;
    while (y)
    {
        if (y & 1) ans *= x;
        x *= x, y >>= 1;
    }
    return ans;
}
void solve()
{
    int n, k;
    cin >> n >> k;
    if (k == 3)
    {
        int ans = 0;
        for (int i = 1; i <= 1e6; i++)
        {
            if (n % i) continue;
            int tmp = n / i - i * i;
            if (tmp % 3) continue;
            tmp /= 3;
            int delta = i * i + 4 * tmp;
            if (delta < 0) continue;
            int os = (int) sqrt(delta);
            if (os * os != delta) continue;
            int x = i + os;
            if (x & 1) continue;
            x /= 2;
            if (x > i) ans++;
        }
        cout << ans << '\n';
    }
    else
    {
        __int128 sum = 1;
        int ans = 0;
        for (int i = 1; sum <= 1e24; i++)
        {
            int tmp = floor(pow(sum - n, 1.0 / k));
            if (sum - ksm(tmp, k) == n)
                ans++;
            sum = ksm(i, k);
        }
        cout << ans << '\n';
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}