#include <iostream> #include <cmath> using namespace std; int incr = 286; int s = 40755; bool esTriangular(int n) { while(s<n) s+=incr, incr++; return s == n; } bool esPentagonal(int x) { double n = (sqrt(24.0*x + 1)+1)/6.0; return n==floor(n); } int main() { int hexa; int id=144 ; while(true) { hexa = id*(2*id -1 ); if(esPentagonal(hexa) && esTriangular(hexa)) { cout << hexa<<endl; return 0; } id++; } return 0; }
No hay comentarios:
Publicar un comentario