Advertisement
FractalFusion

Is 65536 the only power of 2 without digits 1,2,4,8?

Jul 29th, 2016
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.97 KB | None | 0 0
  1. //This program checks values n up to 10^10 for which the last (up to) 51 digits of 16^n are all 0,3,5,6,7,9.
  2. //This program was written to attempt to find a power of 2 other than 65536 which does not contain any digit 1,2,4,8.
  3. //This program only finds two candidates (n=7525657339 and 9881236075) but checking their first few digits via the logarithm method shows that they don't work.
  4. //Based on http://tasvideos.org/forum/viewtopic.php?p=437945#437945
  5.  
  6. #include <stdio.h>
  7. #include <stdint.h>
  8. #include <cmath>
  9.  
  10. int main()
  11. {
  12.     uint64_t val1=1ULL;
  13.     uint64_t val2=0ULL;
  14.     uint64_t val3=0ULL;
  15.     uint64_t carry1,carry2;
  16.    
  17.     for(uint64_t i=1;i<=10000000000ULL;i++)
  18.     {
  19.         val1*=16ULL;
  20.         carry1=val1/100000000000000000ULL;
  21.         val1%=100000000000000000ULL;
  22.         val2=val2*16ULL+carry1;
  23.         carry2=val2/100000000000000000ULL;
  24.         val2%=100000000000000000ULL;
  25.         val3=val3*16ULL+carry2;
  26.         val3%=100000000000000000ULL;
  27.                
  28.         //check last 17 digits of val1 are all 0,3,5,6,7,9
  29.  
  30.         uint64_t c=val1;
  31.         //ones digit is always 6
  32.         c/=10ULL;
  33.  
  34.         int flag=1;
  35.         for(int j=1;j<=16;j++)
  36.         {
  37.             int digit=(int)(c%10ULL);
  38.             if(digit==1 || digit==2 || digit==4 || digit==8)
  39.             {
  40.                 flag=0;
  41.                 break;
  42.             }
  43.             c/=10ULL;
  44.         }
  45.         if(flag==1)
  46.         {
  47.             //check last 17 digits of val2 are all 0,3,5,6,7,9
  48.            
  49.             c=val2;
  50.             for(int j=1;j<=17;j++)
  51.             {
  52.                 int digit=(int)(c%10ULL);
  53.                 if(digit==1 || digit==2 || digit==4 || digit==8)
  54.                 {
  55.                     flag=0;
  56.                     break;
  57.                 }
  58.                 c/=10ULL;
  59.             }
  60.             if(flag==1)
  61.             {
  62.                 //check last 17 digits of val3 are all 0,3,5,6,7,9
  63.            
  64.                
  65.                 c=val3;
  66.                 for(int j=1;j<=17;j++)
  67.                 {
  68.                     int digit=(int)(c%10ULL);
  69.                     if(digit==1 || digit==2 || digit==4 || digit==8)
  70.                     {
  71.                         flag=0;
  72.                         break;
  73.                     }
  74.                     c/=10ULL;
  75.                 }
  76.                 if(flag==1)
  77.                     printf("%llu %llu %017llu %017llu\n",i,val3,val2,val1);
  78.                
  79.             }
  80.            
  81.            
  82.            
  83.            
  84.         }
  85.        
  86.         if(i%100000000ULL==0) printf(".");
  87.        
  88.     }
  89.    
  90.     printf("Done!");
  91.     getchar();
  92.     return 0;
  93.    
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement