At the beginning, I wanted to use the idea of violence, from-R to R, then a look at the data, destroying the data too large. Then think of optimization, the circle plus coordinates can be abstracted into equal eight pieces, so only demand from the square root of the two r to the whole point of R to meet the requirements, but still timed out, and then carefully analyzed a bit later found that this is a mathematical problem, explained as follows:
According to the above description the procedure is as follows:
#include <cstdio>#include<Set>#include<utility>#include<cmath>using namespacestd;Set<pair<int,int> >s;Long Long intR; voidSearchintXinty) { if(%4!=1)return; intSX=SQRT (x/2); for(intI=1; i<=sx;i++) { intT=SQRT (x-i*i); if(t*t==x-i*i) {inttx=t*t-i*i,ty=2*t*i; if(tx>0) { if(tx<ty) { inttmp=tx;tx=ty;ty=tmp; } S.insert (Make_pair (TX*y,ty*y)); } } }} intMain () {scanf ("%d",&R); intSr=sqrt (R); for(intI=1; i<=sr;i++) { if(! (r%i) {Search (I,r/i); if(i*i!=r) Search (r/i,i); }} printf ("%d\n", S.size () *8+4); return 0;}
Thank you for watching, hope to have some gains, thank you.
Bzoj 1041 The hour on the circle