// Author: Jose Aranda, 2024. // Public Domain source code. // // OEIS Sequence A006991 // Make: // g++ -march=native -Wextra -Ofast -o p8.exe p8.cpp // -static // Code modules: // 01 INIT // 02 Fill Vectors // 03 Evaluate n #pragma pack(16) #include #include #include #include #include #include #include #include using namespace std; // I32 integers only 9 full digits. typedef std::int_fast64_t I64; typedef std::int_fast32_t I32; // n odd: a A1, b A2 // n even: a A3, b A4 static vector A1,A2,A3,A4; static vector VX2; // function is SquareFree(p) bool isSF(const I32 p) __attribute__((const)); bool isSF(const I32 p) { if(p>49) { if(p%4 ==0)return false; if(p%9 ==0)return false; if(p%25 ==0)return false; if(p%49 ==0)return false; if(p%121==0)return false; } const double a= (double)p; const double b= sqrt(a); const I32 c= floor(b)+1; for(I32 s= c;s>=2;s--) { if(p%s>0)continue; const I32 ps = p/s; if((ps%s)==0) return false; } return true; // squarefree } // print one term void toprinter(I32 qqqq,I64 n) { cout<8) { cout<<" Last must be between 1,8"<=ASIZE)break; for(I32 x= 0;x< CLIM;x++) { I64 x2= (I64)VX2[x]; I64 tx2= (x2<<1); I64 txz28= tx2 + tz8; if(txz28 >= ASIZE)break; for(I32 y= 0;y< CLIM;y++) { I64 y2 = (I64)VX2[y]; // I64 tyz18= y2+tz8; if(tyz18 >= ASIZE)break; I64 txyz218= tyz18 + tx2; if(txyz218 >= ASIZE)break; I32 pval=1; // weight value if(x>0)pval= pval<<1; if(y>0)pval= pval<<1; if(z>0)pval= pval<<1; // P=(x,y,z) // A1 n1 = (2,1, 8)*P A072068 odd n, a== 2*b // A2 n2 = (2,1,32)*P A072069 odd n, b // A3 n3 = (4,1, 8)*P A072070 even n, a==2*b // A4 n4 = (4,1,32)*P A072071 even n, b // n1 (2,1,8) I64 n1= txyz218; if(n1 lastprinted)break; // evaluate this number const bool bisSF= isSF(br);if(!bisSF)continue; // br==n and is squarefree I32 n= br; // case n mod 8 const int nm8= n%8; // Never const bool ism04= (nm8==0 || nm8==4); if(ism04)continue; // Always const bool ism567= (nm8>=5 && nm8<=7); if(ism567) { qqqq++; toprinter(qqqq,br); qm567++;continue; } // Unknown. mod8 1,2,3. const bool even= (n%2==0); I32 a,b; // even a A3 b A4 // odd a A1 b A2 if(even) { // look i=(n/2). auto i= (n>>1); a =A3[i];b =A4[i]; } else { auto i= n; a =A1[i];b =A2[i]; } // n by the Tunnell Theorem criteria. // and YES (0,0) match. if(a==(b<<1)) { qqqq++; toprinter(qqqq,br); qm123++; } } // close br for return 0; }