题意:
给定自然数n,求满足$\displaystyle \sqrt{x-\sqrt{n}}=\sqrt{z}-\sqrt{y}$的x,y,z,输出解的个数以及所有解 xyz的和
n<=1e9,t<=5000,1500ms
思路:
$\displaystyle x-\sqrt{n}=z+y-2\sqrt{yz}$
$if \sqrt{n}\quad is\quad rational \quad number:$
$\qquad at\quad least\begin{Bmatrix}
x=\sqrt{n}+z\\
y=0
\end{Bmatrix}$
$else \begin{Bmatrix}
n = 4yz\\
x=y+z\\
x^2 \geq n
\end{Bmatrix} \quad infty$
$which\quad is$
$\displaystyle
\begin{Bmatrix}
yz = \frac{n}{4}\\
(y+z) \geq n
\end{Bmatrix}$
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional> #define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x)) using namespace std; typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL; const db eps = 1e-;
const int mod = 1e9+;
const int maxn = 2e6+;
const int maxm = 2e6+;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0); int main() {
int t;
scanf("%d", &t);
while(t--){
int n;
scanf("%d", &n);
if((int)sqrt(n)*sqrt(n)==n){
printf("infty\n");
}
else{
if(n%!=){
printf("0 0\n");
}
else{
int cnt = ;
ll ans = ;
int m = sqrt(n/+0.5);
int c = sqrt(m);
for(int i = ; i <= m; i++){
if((n/)%i==&&((i+(n/)/i)>=c)){ ans += 1ll*i*(n/)/i*(i+(n/)/i);
cnt++;
ans%=mod;
}
}
printf("%d %lld\n",cnt,ans);
}
}
}
return ;
}
这题卡long long的。。
代码: