将所有的组合方式分成两组,其中一组存在哈希表里,这样时间复杂度就降为了2*n*n。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#define mem(a,x) memset(a,x,sizeof(a))
#define s1(x) scanf("%d",&x)
#define s2(x,y) scanf("%d%d",&x,&y)
#define s3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s4(x,y,z,k) scanf("%d%d%d%d",&x,&y,&z,&k)
#define ff(a,n) for(int i = 0 ; i < n; i++) scanf("%d",a+i)
#define tp(x) printf("x = %d\n",x)
#define ansp(x) printf("%d\n",x)
#define ls 2*rt
#define rs 2*rt+1
#define lson ls,L,mid
#define rson rs,mid+1,R
#define ll long long
using namespace std;
typedef pair<int,int> pii;
const ll inf = 0x3f3f3f3f;const int mx = 1e6+4;
int ha[mx*2],x[101];
int a,b,c,d;
ll ans;
int main(){//int T=10; scanf("%d",&T);for(int i = 1; i <= 100; i++)x[i] = i*i;while(scanf("%d%d%d%d",&a,&b,&c,&d) != EOF){mem(ha,0);for(int i = 1; i <= 100; i++)for(int j = 1; j <= 100; j++){ha[a*x[i]+b*x[j]+mx]++; }ans = 0;for(int i = 1; i <= 100; i++)for(int j = 1; j <= 100; j++){ans += ha[-c*x[i]-d*x[j]+mx]; }cout<<ans*16<<endl;}return 0;
}