And the bzoj1041 round is very similar to the hour
Just change a to 3*a*a enumeration. This violence 233 runs too slow
#include <cstdio> #include <cstdlib> #include <algorithm> #include <cmath> using namespace std;
typedef long Long LL;
inline ll Jud (ll x) {ll isqr=sqrt (x);
if (isqr*isqr==x) return ISQR;
return-1;
ll N,ans;
ll GCD (ll A,ll b) {if (a<b) return GCD (B,a); Return b?
GCD (b,a%b): A;
} inline void Calc (ll d) {ll c=2*n/d,a,b,a,b;
for (b=1;b*b<=c;b++) if ((c-b*b)%3==0 && (A=jud ((c-b*b)/3)) >0) {a=3*a*a;
B=b*b;
if (a!=b && Gcd (a,b) ==1) if ((b-a)%2==0 | | d%2==0) {/ll x=abs (b*d-a*d) >>1,y=jud (A*B*D*D/3);
ans++;
int main () {ll d,q;
Freopen ("T.in", "R", stdin);
Freopen ("T.out", "w", stdout);
scanf ("%lld", &q);
while (q--) {ans=0; scanf ("%lld", &n);
N=abs (N);
if (n==0) {printf ("1\n"); continue;
for (d=1;d*d<2*n;d++) if (2*n%d==0) Calc (d), Calc (2*n/d);
if (d*d==2*n) Calc (d);
ans*=4;
ans+=2;
if (n%3==0 && Jud (N*N/3)!=-1) ans+=2; printf ("%lld\ n ", ans);
return 0; }