2
1
Fork 0
aoc2021/17/solution.c

23 lines
989 B
C

#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
int main(
){int C=0,a ,b,c,d,X,Y;scanf("%*[^=]=%i..%i, "
"y=%i..%i",&a,&b ,&c,&d);for(X=sqrt(a*2);X<=b;X++){
#pragma omp parallel for schedule (static\
,256) reduction (+:C)
for(Y= c;Y<-c
;Y++){ int x=0
,y=0,v =X,V=Y
;while (x<b
&&y>c &&(x<a
||y>d) ){x+=v
;y+=V; v=v>0?
v-1:0; V--;}C
+=(x>= a&&x<=b
&&y>=c&&y <=d);}}
printf("Silver: %lld\nGo" "ld: %d"
"\n",(llabs(c)-1)*llabs(c) /2,C);}