fork download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #include <time.h>
  6.  
  7. double getTime(){
  8. struct timeval tv;
  9. gettimeofday(&tv, 0);
  10. return tv.tv_sec + tv.tv_usec * 1e-6;
  11. };
  12.  
  13. int main (void) {
  14. double stime=getTime();
  15. int64_t c, r, x, y, aux;
  16. c=0;
  17. aux=0;
  18. r = 968790360;
  19. //calcular r*r para ser mais rápido, sr ponto de partida dos x, e last é o maior y tal que (x-1)*(x-1) + y*y <= r
  20. //last = r/sqrt(2) porque sqrt(r*r - r/sqrt(2)) = r/sqrt(2)
  21. int64_t r2=r*r,sr=r/sqrt(2) + 1,last=sr-1;
  22. for(x=sr;x<=r;x++) {
  23. y=sqrt(r2 - x*x); //calcula maior y tal que x*x + y*y <= r
  24. c+=2*y+1; //soma 1 por cada ponto (x',y') x'=x, -y <= y' <= y
  25. c+=(last-y)*(2*(x-1)+1); // soma 1 por cada ponto (x',y'), y < x' <= last, -(x-1) <= y' <= x-1
  26. last=y;
  27. }
  28. c=2*c+2*r+1; //c=2*c porque apenas tivemos em conta os pontos x>0, +2*r+1 porque x=0 dá -r <= y' <= r
  29. printf("%lld\n%lf\n",c,getTime()-stime);
  30. c = (c * 0x671659AD2B395A35LLU) ^ 0x6A657B39259F7846LLU;
  31. printf("send solution and cv to: %.8s@grupopie.com\n", (char *) &c);
  32. return 0;
  33. }
Success #stdin #stdout 14.24s 1720KB
stdin
Standard input is empty
stdout
2948556744125085325
14.241655
send solution and cv to: welldone@grupopie.com