Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- FILE *f=fopen("points.in","r");
- FILE *g=fopen("points.out","w");
- long long n=0;
- int r,x0,y0,x1,y1,x;
- fscanf(f,"%d",&r);
- for(x0=0,y0=r,x1=0,y1=r;x0!=r;x0=x1,y0=y1)
- {
- int circ=0,yCirc=y0,line=0,yLine=y0;
- /// gasim urmatorul punct (x1, y1) pe cerc, mentinand
- /// limita inferiosara din cerc
- do
- {
- circ +=2*x1+1,++x1;
- while(circ>0)
- circ-=2*y1-1,--y1;
- } while(circ);
- /// adaugam contributia pentru punctele (x, *) cu x0 <= x < x1
- /// acest lucru poate fi calculat usor prin mentinerea limitei inferioare
- /// pentru cerc si linia (x0, y0) <-> (x1, y1)
- for(x=x0;x<x1;++x)
- {
- circ+=2*x+1;
- while(circ>0)
- circ-=2*yCirc-1,--yCirc;
- line-=y1-y0;
- while(line>0)
- line-=x1-x0,--yLine;
- n+=yCirc-yLine;
- }
- }
- fprintf(g,"%lld",4*n);
- fclose(f);
- fclose(g);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement