When you subtract the sum of the squares of the digits of the number from the original number it gives you another prime number squared.
2026-04-25 15:09:52.1777129792
On
On
Find 7 digit prime numbers with this property;
2.4k Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
3
There are 3 best solutions below
3
On
My previous solution was not checking that the numbers are prime, just that $n - \!\!\!\!\!\!\!\!\sum\limits_{\text{digits $d$ of $n$}} d^2$ are.
So, in Mathematica:
n = 7;
Select[Range[10^(n - 1) + 1, 10^n - 1, 2],
And[
PrimeQ[#1],
PrimeQ[Sqrt[#1 - Apply[Plus, IntegerDigits[#1]^2]]]
] &
]
Output:
{1100509, 1585201, 1661789, 2211257, 4541309, 4871077, 4897709,
5340949, 5958751, 7393123, 8185501, 8744003}
8
On
The primes from $1000$ to $10^8$ with that property (and the corresponding root) are:
(2903,53)
(3533,59)
(3803,61)
(5197,71)
(9533,97)
(18973,137)
(24763,157)
(37321,193)
(73561,271)
(96953,311)
(113621,337)
(124777,353)
(129097,359)
(134837,367)
(139241,373)
(398341,631)
(830003,911)
(1100509,1049)
(1585201,1259)
(1661789,1289)
(2211257,1487)
(4541309,2131)
(4871077,2207)
(4897709,2213)
(5340949,2311)
(5958751,2441)
(7393123,2719)
(8185501,2861)
(8744003,2957)
(11485559,3389)
(15343039,3917)
(15343079,3917)
(16008193,4001)
(16459441,4057)
(16736519,4091)
(17648693,4201)
(17901563,4231)
(21077401,4591)
(22915511,4787)
(22915591,4787)
(25877861,5087)
(26553629,5153)
(28058447,5297)
(28058467,5297)
(30261149,5501)
(32137747,5669)
(33443269,5783)
(34304561,5857)
(36954461,6079)
(40360753,6353)
(43073159,6563)
(43309751,6581)
(47375963,6883)
(47596441,6899)
(48762557,6983)
(53743763,7331)
(56505481,7517)
(62141909,7883)
(65496941,8093)
(67782521,8233)
(76510171,8747)
(80982263,8999)
(82864927,9103)
(83302253,9127)
(84401197,9187)
(85027057,9221)
(86360003,9293)
(90992939,9539)
(95394619,9767)
(96373819,9817)
Code (Haskell):
module Main (main) where
import Math.NumberTheory.Primes
import Math.NumberTheory.Powers
import Control.Monad (guard)
import System.Environment (getArgs)
main :: IO ()
main = do
args <- getArgs
let (lo,hi) = case args of
a:b:_ -> (read a, read b)
a:_ -> (1000, read a)
_ -> (1000, 10^7)
mapM_ print $ funPrimes lo hi
digitSquareSum :: Integer -> Integer
digitSquareSum = go 0
where
go acc 0 = acc
go acc m = case m `quotRem` 10 of
(q,r) -> go (acc + r*r) q
rootPrime :: Integer -> Maybe Integer
rootPrime n = do
let m = n - digitSquareSum n
r <- exactSquareRoot m
guard (isPrime r)
return r
funPrimes :: Integer -> Integer -> [(Integer, Integer)]
funPrimes low high = takeWhile (<= high) (sieveFrom low) >>= \p ->
case rootPrime p of
Just r -> [(p,r)]
Nothing -> []
Between $10^8$ and $10^9$, we have
(105411479,10267)
(110271107,10501)
(111492631,10559)
(111492671,10559)
(116014531,10771)
(116014571,10771)
(117787913,10853)
(117787993,10853)
(117961573,10861)
(120846227,10993)
(134258869,11587)
(148767061,12197)
(149793487,12239)
(156325123,12503)
(161010841,12689)
(161366489,12703)
(165199973,12853)
(166900837,12919)
(167780441,12953)
(169078339,13003)
(169234399,13009)
(171846139,13109)
(184878781,13597)
(187334143,13687)
(188485741,13729)
(199007723,14107)
(207043433,14389)
(207677111,14411)
(208023083,14423)
(209641673,14479)
(214300417,14639)
(218182633,14771)
(221384893,14879)
(235039859,15331)
(235899239,15359)
(238486597,15443)
(242082611,15559)
(247338829,15727)
(258020197,16063)
(258791927,16087)
(258791987,16087)
(262083953,16189)
(267944477,16369)
(270701371,16453)
(275792723,16607)
(276191479,16619)
(286320427,16921)
(286320487,16921)
(288354637,16981)
(288762337,16993)
(312193733,17669)
(312688781,17683)
(316519933,17791)
(319730353,17881)
(328298413,18119)
(343694849,18539)
(357928927,18919)
(359443943,18959)
(365612881,19121)
(368909131,19207)
(371217443,19267)
(371217463,19267)
(393744983,19843)
(399720367,19993)
(417916507,20443)
(424319009,20599)
(441798719,21019)
(454414673,21317)
(462981581,21517)
(472497401,21737)
(475371007,21803)
(486776309,22063)
(486952877,22067)
(487482577,22079)
(490932931,22157)
(500282917,22367)
(503598839,22441)
(508187159,22543)
(508457681,22549)
(511619333,22619)
(511709977,22621)
(520615621,22817)
(520615681,22817)
(524730821,22907)
(532271219,23071)
(562591219,23719)
(565155733,23773)
(575088641,23981)
(575088799,23981)
(622153489,24943)
(648364667,25463)
(658281941,25657)
(671794927,25919)
(671794987,25919)
(702939491,26513)
(726464467,26953)
(739350793,27191)
(744362309,27283)
(785737283,28031)
(808435721,28433)
(811851211,28493)
(863360941,29383)
(864419033,29401)
(878589319,29641)
(940097269,30661)
(949194871,30809)
(959946707,30983)
(968641477,31123)
(974876041,31223)
(978251059,31277)
(990801919,31477)
$111$ more. So these beasts are rare, but there are enough.
EDIT:
Okay, here's my solution:
Ugly code, but I get:
Let's check 37321. We get 37321 - 3² - 7² - 3² - 2² - 1², whose square root is 193, which is prime.
For 7 digits, here's what I have so far:
Let's check 1100509. We get sqrt(1100509 - 1 - 1 - 25 - 81) = 1049, which is prime. Feel free to expend more CPU cycles to get more.