#include #include #include #define __STDC_IEC_559__ #include #include #include ///========================================================= char ma[64]; const char *flnm="A348169.txt"; ///description char filename[64]; ///some usefull text symbols const char *ws="=============================="; const char *ws2=" ("; const char *ws3=") "; const char *ws0=" "; const char *ws6=",";//10 const char *ws7="*";//10 const char tab = '\t'; const char *header="a(n) (x,y,z) A, B"; int rj = 2573;// new line char devd =9;////table devider unsigned long a_n[1024]; /// results for b-file for OEIS (just in case) ///========================================================= /// helper functions long gcd(long a, long b) { if (b == 0) return a; else return gcd(b, a % b); } ///========================================================= ///========================================================= void perform() { // some indexes long count=1; unsigned long prev_N=0, prev_A=0, prev_B=0; memset((char*) &a_n[0], 0, 1024*sizeof(unsigned long)); memset(&filename[0],0,64); strcpy(&filename[0],flnm); //optional CreateDirectory("A348169",NULL); SetCurrentDirectory("A348169"); HFILE hndF1= _lcreat(filename,0); memcpy(&filename[0],"b", sizeof(char)); HFILE hndF2= _lcreat(filename,0);//b-file // header if needed _lwrite(hndF1,(const char*)header, strlen(header));// _lwrite (hndF1, (LPSTR) &rj, 2);// new line //==================================================== //main cycles long main_cycle=900; float e_cycle= (float) (100./main_cycle); // to display performance in percentage for (unsigned long N=1 ;N< main_cycle;++N) // N=a(n) to be searched { long limi = 3.*pow(N,0.5); //to be on safe side for (unsigned long x=1 ;x< limi;++x) // 2 { for (unsigned long y=1;y< limi;++y) // 3 { for (unsigned long z=1 ; z< limi;++z) // 4 { for (long A=1 ;A< 600;++A) // one may want to play with the limits { for (long B=1 ;B< 600;++B) // { unsigned long N_1 =A*(x*x+y*y+z*z); unsigned long N_2= B* (x*y+ x*z + y*z); if ((N_1==N_2) && (gcd(A, B)==1) && (N==N_1)) { // check if it is permutation of previously found "quintet" // one may want check repeating values in the sequence (like number 72 which appears twice) then run this: // if ( ( (prev_N==N) && ( (prev_A!=A)&& (prev_B!=B) ) ) || (prev_N!=N) ) if (prev_N!=N) // /// for non repeating { prev_N=N; prev_A=A; prev_B=B; /// table to file ///==================== memset(&ma[0],0,32); ltoa( N, ma,10); _lwrite(hndF1,(const char*)&ma[0],sizeof(char)*strlen(&ma[0]) );/// _lwrite(hndF1,&tab, sizeof(char));// , _lwrite(hndF1,ws2, 2*sizeof(char));// , ///==================== memset(&ma[0],0,32); ltoa( x , ma,10); _lwrite(hndF1,(const char*)&ma[0],sizeof(char)*strlen(&ma[0]) );/// _lwrite(hndF1,ws6, sizeof(char));// , ///==================== memset(&ma[0],0,32); ltoa( y, ma,10); _lwrite(hndF1,(const char*)&ma[0],sizeof(char)*strlen(&ma[0]) );/// _lwrite(hndF1,ws6, sizeof(char));// , ///==================== memset(&ma[0],0,32); ltoa( z, ma,10); _lwrite(hndF1,(const char*)&ma[0],sizeof(char)*strlen(&ma[0]) );/// _lwrite(hndF1,ws3, 2*sizeof(char));// ) ///==================== A,B _lwrite(hndF1,&tab, sizeof(char));// memset(&ma[0],0,32); ltoa(A, ma,10); _lwrite(hndF1,(const char*)&ma[0],sizeof(char)*strlen(&ma[0]) );/// _lwrite(hndF1,ws6, 2*sizeof(char));// , ///==================== memset(&ma[0],0,32); ltoa(B, ma,10); _lwrite(hndF1,(const char*)&ma[0],sizeof(char)*strlen(&ma[0]) );/// //_lwrite(hndF1,ws3, 2*sizeof(char));// , _lwrite (hndF1, (LPSTR) &rj, 2);/// new line /// write to b-file at the same time // number memset(&ma[0],0,32); ltoa( count++, ma,10); _lwrite(hndF2,(const char*)&ma[0],sizeof(char)*strlen(&ma[0]) );/// //_lwrite(hndF2,&tab, sizeof(char));// _lwrite(hndF2," ", sizeof(char)); //number = value memset(&ma[0],0,32); ltoa( N, ma,10); _lwrite(hndF2,(const char*)&ma[0],sizeof(char)*strlen(&ma[0]) );/// // new line _lwrite (hndF2, (LPSTR) &rj, 2);/// new line } } }/// } } } } printf( "Progress \r%3d%%", (int) ( e_cycle*N) ); fflush(stdout); } /// FINISH CloseHandle(&hndF1); memset(&ma[0],0,32); ShellExecute(0, 0,filename, 0, 0 , SW_SHOW ); } ///==================================================== int main() { perform(); exit(0); return 0; } ///====================================================