Here is code for hexagonal and pentagonal numbers. I need type that stores something bigger than 10 billion. Double works fine to about 8.4 billion. Of course I tried using long long and unsigned long long but it's still not working. Please repair this code because it overflows now matter what I do or explain how to use GMP library. I'm using CodeBlocks 10.5. Best regards.
#include <stdio.h>
#include <math.h>
double Pentagonal(int n){
double P = 0;
P = (3*n*n - n) / 2;
P = -P;
return P;
}
double Equation(){
double x1,x2,remainder = 0;
//where the cycle starts
int n = 166;
//variable for the remainder
int x = 0;
//quadratic equation quotients
int a = 2;
int b = -1;
double c = 0;
for(n; n<33000; n++)
{c = Pentagonal(n);
double expression = b*b - 4*a*c;
printf("\n%.0lf",expression);
double root = sqrt(expression);
x1 = (-b + root)/(2*a);
x = (-b + root)/(2*a);
remainder = fmod(x1,x);
x2 = (-b - root)/(2*a);
if(remainder == 0)
{printf("%.4lf",x1);
printf("\nNumber is %.0lf\n",-c);
break;}
}
return 0;
}
int main(){
Equation();
return 0;
}