abc397D题解
第一次用KaTeX,写的不豪请谅解
题意🤓🤓🤓
给定一个正整数N,问有没有一对正整数(x,y),使
过程😶😶😶
我们可以先化简
设A=x-y,B=xy
因为B可以用A表示出来,所以我们只枚举A就行了🙄💅💅💅
蛋事!!!🤯🤯🤯
A要枚举到哪呢?🤔🤔🤔
如果直接枚举到N那么1e18会让你直接TLE😧😧😧
现在,我们来证明:
代码附上😋😋😋
#include <bits/stdc++.h>
#define int unsigned long long
using namespace std;
const int N = 1e6 + 5;
//因为是三次方所以只枚举到1e6
int n, x, y;
signed main(){
cin >> n;
if(n == 1){
cout << -1;
return 0;
}
for(int i = 1; i * i * i + 3 * i * i <= n; i++){
int k = sqrt(i * i + 4 * ((n - i * i * i) / (3 * i)));//表示x+y
x = (k + i) / 2;
y = (k - i) / 2;
if(x * x * x - y * y * y == n){
cout << x << " " << y;
return 0;
}
}
cout << -1;
return 0;
}