题意:
给定自然数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-2sqrt{yz}$
$if sqrt{n}quad isquad rational quad number:$
$qquad atquad leastegin{Bmatrix}
x=sqrt{n}+z\
y=0
end{Bmatrix}$
$else egin{Bmatrix}
n = 4yz\
x=y+z\
x^2 geq n
end{Bmatrix} quad infty$
$whichquad is$
$displaystyle
egin{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-6; const int mod = 1e9+7; const int maxn = 2e6+100; const int maxm = 2e6+100; 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 "); } else{ if(n%4!=0){ printf("0 0 "); } else{ int cnt = 0; ll ans = 0; int m = sqrt(n/4+0.5); int c = sqrt(m); for(int i = 1; i <= m; i++){ if((n/4)%i==0&&((i+(n/4)/i)>=c)){ ans += 1ll*i*(n/4)/i*(i+(n/4)/i); cnt++; ans%=mod; } } printf("%d %lld ",cnt,ans); } } } return 0; }
这题卡long long的。。
代码: