0

In the following problem I have to find the number > 40755 which is triangular,pentagonal and hexagonal. The formulas for these type of numbers are given below. As I read every hexagonal number is also triangular so we have to compare pentagonal with hexagonal numbers. This algorithm gives 9 digit number 969480682 for about 20 minutes which is too slow. Any help concerning the speed and corectness will be greatly appreciated.

```
#include <stdio.h>
int Pentagonal(int n){
int P = 0;
P = (3*n*n - n) / 2;
return P;
}
int Hexagonal(int m){
int H = 0;
H = m*(2*m - 1);
return H;
}
void compare(int P,int H){
if(P == H)
{printf("\n%d",H);
}
}
int main(){
for(int i = 100; i<100000; i++)
{
for(int j = 100; j<100000; j++)
{
compare(Pentagonal(i),Hexagonal(j));
}
}
return 0;
}
```

*Edited 5 Years Ago by george61*: n/a