All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Palindrome factors (Posted on 2022-03-15) Difficulty: 3 of 5
Six of the factors of 1221 are palindromes: {1,3,11,33,111,1221} but two are not: {37,407}

(A) What number under one million has the most palindrome factors?

Some numbers have only palindromes as factors. Examples include 88: {1,2,4,8,11,22,44,88} and any palindromic prime

(B) Find the smallest number with at least as many palindrome factors as part (A) but having only palindrome factors.

No Solution Yet Submitted by Jer    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Some Thoughts part (A) solution and an attempt at (B) | Comment 2 of 8 |
Part 1:

max=[0 0]; clc
for n=1:1000000
   k=1:ceil(sqrt(n));
   f=k(rem(n,k)==0);
   f2=n./f;
   if f(end)==f2(end)
       f=[f f2(1:end-1)];
   else
       f=[f f2];
   end
   ct=0;
   for i=1:length(f)
      if isPalin(f(i))
         ct=ct+1; 
      end
   end
 %  disp([n ct])
   if ct>max(end,2)
      max=[max;[n ct]]; 
      disp([n ct length(f)])
      for i=1:length(f)
          if isPalin(f(i))
              fprintf('%4d ',f(i))
          end
      end
      disp(' ')
   end
end
disp(max)

function ip=isPalin(x)
  s=char(string(x));
  bynd=length(s)+1;
  ip=true;
  for i=1:floor(length(s)/2)
     if  s(i)~=s(bynd-i)
        ip=false;
        break
     end
  end
end

finds

      792792          39         144
   1    2    3    4    6    7    8    9   11   22   33   44   66   77   88   99  121  242  252  363  484  616  858 99099 88088 66066 44044 33033 22022 11011 9009 8008 6776 6006 4004 3003 2772 2002 1001  

indicating 39 palindromic divisors of 792792 out of a total of 144 divisors. The palindromic divisors are then listed.

Part 2:

max=[0 0]; clc
for n0=1:100000 
   ns=char(string(n0));
   ns1=ns;
   for i=length(ns):-1:1
      ns1=[ns1 ns(i)] ;
   end
   n1=str2double(ns1);
   ns2=ns;
   for i=length(ns)-1:-1:1
      ns2=[ns2 ns(i)] ;
   end 
   n2=str2double(ns2);
   for n=[n1 n2]
       k=1:ceil(sqrt(n));
       f=k(rem(n,k)==0);
       f2=n./f;
       if f(end)==f2(end)
           f=[f f2(1:end-1)];
       else
           f=[f f2];
       end
       ct=0; good=true;
       for i=1:length(f)
           if isPalin(f(i))
               ct=ct+1;
           else
               good=false;
           end
       end
       if good==false
           continue
       end
       %  disp([n ct])
       if ct>max(end,2)
           max=[max;[n ct]];
           disp([n ct length(f)])
           for i=1:length(f)
               if isPalin(f(i))
                   fprintf('%4d ',f(i))
               end
           end
           disp(' ')
       end
   end
end
% disp(max)

function ip=isPalin(x)
  s=char(string(x));
  bynd=length(s)+1;
  ip=true;
  for i=1:floor(length(s)/2)
     if  s(i)~=s(bynd-i)
        ip=false;
        break
     end
  end
end

Finds only as many as 18 such divisors:

      448844          18          18
   1    2    4   11   22   44  101  202  404 448844 224422 112211 40804 20402 10201 4444 2222 1111  


having tested through 10-digit palindromes, as one of the palindromic divisors needs to be the number itself. Trying for more digits would take much longer to run.

  Posted by Charlie on 2022-03-15 09:22:53
Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (9)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information