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

Home > Algorithms
Divisible by Prime Power (Posted on 2023-05-15) Difficulty: 3 of 5
Define d(x) as sum of the digits of x, where x is a hexadecimal positive integer.
d(d(x)) denotes the sum of digits of d(x).

For example, when x=(ABC)16
Then, d(x) = (A)16+(B)16+(C)16 = (21)16
and, d(d(x)) = 2 + 1 = 3

Consider the first 1011 (base ten) values of a hexadecimal prime number N.

Devise an algorithm such that:
• Each of d(N) and d(d(N)) is divisible by a prime power.
Note: A prime power is a number of the form pn, where p is a prime number, and n is an integer greater than 1.

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution computer solution Comment 1 of 1
clearvars,clc
ct=0;
for n0=1:1011
  n=nthprime(n0);
  hex=[];
  while n>0
    q=floor(n/16);
    r=n-16*q;
    hex=[r hex];
    n=q;
  end
  n=hex;
  d=sum(n);
  f=factortable(d);
  q=f(:,1);
  q=q(q>1);
  if length(q)>0
    n=d;
    hex=[];
    while n>0
      q=floor(n/16);
      r=n-16*q;
      hex=[r hex];
      n=q;
    end
    n=hex;
    dd=sum(n);
    f=factortable(dd);
    q=f(:,1);
    q=q(q>1);
    if length(q)>0
      ct=ct+1;
      fprintf('%4d %7d  %5s %3d %3d\n',n0,nthprime(n0),dec2base(nthprime(n0),16),d,dd)
    end
  end
end
ct

finds 22 such primes in the range specified

ordinal         prime
prime   prime  in hex d  dd
   8      19     13   4   4
   9      23     17   8   8
  16      53     35   8   8
  23      83     53   8   8
  30     113     71   8   8
  56     263    107   8   8
  62     293    125   8   8
  71     353    161   8   8
 103     563    233   8   8
 108     593    251   8   8
 136     769    301   4   4
 137     773    305   8   8
 208    1283    503   8   8
 245    1553    611   8   8
 565    4099   1003   4   4
 568    4129   1021   4   4
 569    4133   1025   8   8
 597    4373   1115   8   8
 627    4643   1223   8   8
 632    4673   1241   8   8
 687    5153   1421   8   8
 711    5393   1511   8   8
ct =
    22

That's all there was found through the 1011th prime.

To get some real hex digits you need to go higher:

1029    8209   2011   4   4
1035    8243   2033   8   8
1038    8273   2051   8   8
1061    8513   2141   8   8
1092    8753   2231   8   8
1114    8963   2303   8   8
1174    9473   2501   8   8
1470   12289   3001   4   4
1472   12323   3023   8   8
1581   13313   3401   8   8
1905   16433   4031   8   8
1929   16673   4121   8   8
2312   20479   4FFF  49   4
2313   20483   5003   8   8
2338   20753   5111   8   8
2726   24593   6011   8   8
3124   28669   6FFD  49   4
3485   32479   7EDF  49   4
3511   32719   7FCF  49   4
3512   32749   7FED  49   4
3808   35839   8BFF  49   4
3855   36319   8DDF  49   4
3876   36559   8ECF  49   4
4172   39679   9AFF  49   4
4222   40189   9CFD  49   4
4239   40429   9DED  49   4
4260   40639   9EBF  49   4
4263   40699   9EFB  49   4
4281   40879   9FAF  49   4
4287   40939   9FEB  49   4
4557   43759   AAEF  49   4
4583   44029   ABFD  49   4
4608   44269   ACED  49   4
4671   44959   AF9F  49   4
4907   47599   B9EF  49   4
4934   47869   BAFD  49   4
4952   48079   BBCF  49   4
4954   48109   BBED  49   4
4998   48589   BDCD  49   4

(The d and dd are shown in decimal, and 49 decimal is 31 in hex, whose digits add to 4.)

The first one exhibiting "real" hex digits is shown by

2312   20479   4FFF  49   4

where the hex representation of the 2312th prime is 4FFF, so the digits add to 4+3*15 = 49, which is 7^2, and is represented in hex as 31, which adds up to 4, the square of 2.

  Posted by Charlie on 2023-05-15 13:57:09
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 (8)
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