/*************************************************************************** main.cpp - description ------------------- begin : Wed Dec 31 22:26:46 CST 2003 copyright : (C) |YEAR| by Antonio Alberto Olivares email : tonioolivares@todito.com, olivares14031@yahoo.com ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #ifdef HAVE_CONFIG_H #include <config.h> #endif #include <iostream.h> #include <stdlib.h> #include <math.h> int main(int argc, char *argv[]) { int i; // counter for for loop double j; // A000129 double k; // A000129(n-1) // Formulas for generating pythagorean triples double x; // A001652 or A0046090 x = 2uv, u > v double y; // A001652 or A0046090 y = u^2 - v^2 double z; // A001653 z = u^2 + v^2 cout << " " << '\t' << "A000129" << '\t' << "A000129" << '\t' << "A001652" << '\t' << "A0046090" << " A001653" << "\n"; cout << "N" << '\t' << " " << '\t' << " (n-1)\n" ; cout << "-" << '\t' << "-------" << '\t' << "-------" << '\t' << "-------" << '\t' << "-------" << '\t' << "-------" << '\t' << "\n"; for (i=1; i < 9; i++) // change 9 to whatever number you want if desired { j = (pow((1 + sqrt(2)),i)-pow((1-sqrt(2)),i))/(2*sqrt(2)); // A000129 k = (pow((1 + sqrt(2)),(i-1))-pow((1-sqrt(2)),(i-1)))/(2*sqrt(2)); // A000129(n-1) if ((i % 2 == 0) && (j > k)) // if i is even, then x = u^2-v^2 and y = 2uv { x = pow(j,2) - pow(k,2); y = 2*j*k; } if ((i % 2 != 0) && (j > k)) // if i is odd, then x = 2uv and y = u^2-v^2 { x = 2*j*k; y = pow(j,2) - pow(k,2); } z = pow(j,2) + pow(k,2); // A001653 cout << i << '\t' << j << '\t' << k << '\t' << x << '\t' << y << '\t' << z << '\t' << "\n"; } return EXIT_SUCCESS; }