```#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define gr 1.6180339887498948482  //Golden ratio
typedef long long ll;

int main() {
ll total=0,maxp = 2.5*pow(10,9);
ll mt=1,nt=1,m2=1,n1=1,n2=1,h,d,m1=0;;
printf("\n\n Perimeter:%15.1lld\n",maxp);
d= floor(sqrt(maxp/3));    // Calculate the order of the Farey Seqence

while ((double)m2/n2 <= gr ) {
total= total+floor(maxp/((m2+n2)*(m2+n2)-m2*n2));
h= floor((n1+d)/n2);  // Generate next Farey sequence m2/n2
mt= h * m2 - m1;
nt= h * n2 - n1;
n1=n2;
n2=nt;
m1=m2;
m2=mt;
}

printf(" Triangles found: %15.lld \n",total);
return(0);
}

```

double

```#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define gr 1.6180339887498948482  //Golden ratio

int main() {
double total=0,maxp = 2.5*pow(10,9);
double mt=1,nt=1,m2=1,n1=1,n2=1,h,d,m1=0;;
printf("\n\n Perimeter:%15.1le\n",maxp);
d= floor(sqrt(maxp/3));    // Calculate the order of the Farey Seqence

while (m2/n2 <= gr ) {
total= total+floor(maxp/((m2+n2)*(m2+n2)-m2*n2));
h= floor((n1+d)/n2);  // Generate next Farey sequence m2/n2
mt= h * m2 - m1;
nt= h * n2 - n1;
n1=n2;
n2=nt;
m1=m2;
m2=mt;
}

printf(" Triangles found: %15.lf \n",total);
return(0);
}

```

```#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define gr 1.6180339887498948482  //Golden ratio
typedef long long ll;

int main() {
ll total=0,maxp = 2.5*pow(10,9);
ll mt=1,nt=1,m2=1,n1=1,n2=1,h,d,m1=0;;
printf("\n\n Perimeter:%15.1lld\n",maxp);
d= floor(sqrt(maxp/3));    // Calculate the order of the Farey Seqence

while ((double)m2/n2 <= gr ) {
total= total+(maxp/((m2+n2)*(m2+n2)-m2*n2));
h= ((n1+d)/n2);  // Generate next Farey sequence m2/n2
mt= h * m2 - m1;
nt= h * n2 - n1;
n1=n2;
n2=nt;
m1=m2;
m2=mt;
}

printf(" Triangles found: %15.lld \n",total);
return(0);
}

```

```#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#define gr 1.6180339887498948482  //Golden ratio
typedef long long ll;

int main() {
ll total=0,maxp = 2.5*pow(10,9);
int mt=1,nt=1,m2=1,n1=1,n2=1,h,d,m1=0;;
printf("\n\n Perimeter:%15.1lld\n",maxp);
d= floor(sqrt(maxp/3));    // Calculate the order of the Farey Seqence

while ((double)m2/n2 <= gr ) {
total= total+(maxp/(ll(m2+n2)*ll(m2+n2)-ll(m2)*n2));
h= ((n1+d)/n2);  // Generate next Farey sequence m2/n2
mt= h * m2 - m1;
nt= h * n2 - n1;
n1=n2;
n2=nt;
m1=m2;
m2=mt;
}

printf(" Triangles found: %15.lld \n",total);
return(0);
}

```