challenge - prime numbers where sum of squared digits of prime number is also prime
|
01-05-2018, 01:34 PM
Post: #1
|
|||
|
|||
challenge - prime numbers where sum of squared digits of prime number is also prime
Thought I would see what this looked like.
1) Find the first prime number - ok, this is 2 2) Compute the sum of the squared digits of that prime number 3) Determine if the computed sum is also prime and display it 4) Find the next prime number 5) Goto 2 For example, 11 is the first prime where the sum of its digits squared is also prime (2). What is the next prime where this is true? How many primes less than 1000 is this true for? What is the largest prime less than 100,000 where this is true? Just for curiosity. Enjoy. |
|||
01-05-2018, 02:01 PM
Post: #2
|
|||
|
|||
RE: challenge - prime numbers where …
from a well know wiki
Code: A happy prime is a number that is both happy and prime. The happy primes below 500 are BEST! SlideRule ps: the ellipsis is needed for character length; 87 max, 89 generated |
|||
01-05-2018, 02:02 PM
(This post was last modified: 01-05-2018 03:54 PM by Didier Lachieze.)
Post: #3
|
|||
|
|||
RE: challenge - prime numbers where sum of squared digits of prime number is prime
A quick HP Prime program providing the prime numbers between N & M fitting the requirement:
Code: EXPORT PrCh(N,M) Call it with e.g. SIZE(PrCh(1,1000)) to know for how many primes less than 1000 the sum of squared digits of the number is prime. |
|||
01-05-2018, 03:31 PM
Post: #4
|
|||
|
|||
RE: challenge - prime numbers where sum of squared digits of prime number is also prime
(01-05-2018 02:01 PM)SlideRule Wrote: A happy prime is a number that is both happy and prime. The happy primes below 500 are Hi! Happy PRIMES do not fit what I had asked about. The prime 13 is happy per the list above, but although 13 is prime, 1^2 + 3^2 is 10, which is not prime. ? |
|||
01-05-2018, 03:42 PM
Post: #5
|
|||
|
|||
RE: challenge - prime numbers where sum of squared digits of prime number is also prime
Yup, the "happy number" refers to an entire sequence:
Quote:For example, 19 is happy, as the associated sequence is: At the end of the sequence you must meet the number 1 (one). So it's related to, but different from, the question from the OP Software Failure: Guru Meditation -- Antonio IU2KIY |
|||
01-05-2018, 04:23 PM
Post: #6
|
|||
|
|||
RE: challenge - prime numbers where sum of squared digits of prime number is also prime
Agreed... the Happy / Unhappy number process was used for the programming contest at this past year's HHC meeting.
Here, I'm wondering how many prime numbers have primes as the result of squaring then summing the original prime number's digits. :-) |
|||
01-05-2018, 04:54 PM
Post: #7
|
|||
|
|||
RE: challenge - prime numbers where sum of squared digits of prime number is prime
(01-05-2018 04:38 PM)Mike (Stgt) Wrote:(01-05-2018 01:34 PM)Gene Wrote: How many primes less than 1000 is this true for? Interesting, my program above returns 53 prime numbers below 1000, from 11 to 997: {11,23,41,61,83,101,113,131,137,173,179,191,197,199,223,229,311,313,317,331,337,353,373,379,397,401,409,443,449,461,463,467,601,641,643,647,661,683,719,733,739,773,797,829,863,883,911,919,937,971,977,991,997} |
|||
01-05-2018, 06:18 PM
Post: #8
|
|||
|
|||
RE: challenge - prime nbrs where sum of squared digits of prime number is also prime
(01-05-2018 04:54 PM)Didier Lachieze Wrote:(01-05-2018 04:38 PM)Mike (Stgt) Wrote: 49 I think you will only get those results of you have set the calculator at Fix 0 or the Standard number setting due to the ASC(STRING ()) sequence. Cheers, Terje |
|||
01-05-2018, 08:01 PM
Post: #9
|
|||
|
|||
RE: challenge - prime numbers where sum of squared digits of prime number is prime
(01-05-2018 06:18 PM)Terje Vallestad Wrote: I think you will only get those results of you have set the calculator at Fix 0 or the Standard number setting due to the ASC(STRING ()) sequence. You're right, ASC(STRING (n)) should be replaced by ASC(STRING(n,1)) to work with all number formats. Here is the updated code, including also a fix for the WHILE exit condition: Code: EXPORT PrCh(N,M) |
|||
01-05-2018, 08:37 PM
(This post was last modified: 01-05-2018 09:33 PM by Gilles59.)
Post: #10
|
|||
|
|||
RE: challenge - prime numbers where sum of squared digits of prime number is also prime
User RPL with ListExt Library (https://www.hpcalc.org/details/7971) :
Code: {} 1 same results as Didier "What is the largest prime less than 100,000 where this is true?" Code: 100000 For 1'000'000'000 -> 999'999'667 |
|||
01-06-2018, 02:18 AM
Post: #11
|
|||
|
|||
RE: challenge - prime numbers where sum of squared digits of prime number is also prime
(01-05-2018 08:37 PM)Gilles59 Wrote: Warms my heart, Gilles. I'm starting to think of I→NL as the "challenge and puzzle" command, as it seems to be most useful in those situations. "If the shoe fits..." |
|||
01-06-2018, 05:46 PM
(This post was last modified: 01-07-2018 03:05 PM by wawa.)
Post: #12
|
|||
|
|||
RE: challenge - prime numbers where sum ...
Here is my program for the DM42/Free42/HP42s.
The DM42 gives the answer for 100000 in 4 minutes. Type the limit in X, the program CHALNG returns the number of such primes in X and the last prime found with that property in Y. Ex: 100000 -> X:1818 and Y: 99971 1000 -> X:53 and Y:997 Edit : On the true hp42s, the 1000 chalenge takes 8 minutes to complete. The 100000 is out of reach in a reasonable time. Code: 00 { 239-Byte Prgm } |
|||
01-06-2018, 08:32 PM
Post: #13
|
|||
|
|||
RE: challenge - prime numbers where sum of squared digits of prime number is also prime
(01-06-2018 02:18 AM)DavidM Wrote: I'm starting to think of I→NL as the "challenge and puzzle" command, as it seems to be most useful in those situations. I think that I->NL and the reverse command are helpful a lot if one plays with the digits of a number. The other way is to use string conversion. Wikis are great, Contribute :) |
|||
01-08-2018, 01:58 AM
Post: #14
|
|||
|
|||
challenge - prime numbers where sum of squared digits of prime number is also prime
This program takes an integer from level 1: in the stack and returns the prime that satisfies the condition of the challenge in level 2: and the value of the sum of the digits of the prime squared in level 1:, if flag 1 is set, the prime will be the previous prime or else the next prime. The program is stored in a variable called SDIP.
« WHILE 1 FS? { PREVPRIME } { NEXTPRIME } IFTE {0} OVER →STR WHILE DUP UNROT HEAD OBJ→ + SWAP TAIL DUP SIZE REPEAT END DROP SQ ΣLIST DUP ISPRIME? NOT REPEAT DROP END » SDIP [STO] running the program with flag 1 cleared and 2 on level 1: we have: 2: 11 1: 2 deleting 2 from level 1: and running the program again we have: 2: 23 1: 13 To see how many of such primes are that are less than 1000, we create a little program « 0 1000 1 SF @ SDIP will look for the previous prime WHILE DUP 11 > REPEAT SDIP DROP SWAP 1 + SWAP END DROP » running this program we have: 1: 53 To find the largest of such primes less than 100,000 we set flag 1 and run the program with 100000 in level 1:, we have: 2: 99971 1: 293 |
|||
01-08-2018, 07:43 PM
Post: #15
|
|||
|
|||
challenge - prime numbers where sum of squared digits of prime number is also prime
Hi, Gene:
Just saw this challenge you posted and decided to give it a try on my trusty HP-71B plus JPC ROM emulator. Quote:What is the next prime where this is true? This 109-byte, 3-liner will print all elements up to a given limit: 1 INPUT Z @ N=2 @ LOOP @ N=FPRIM(N+1) @ IF N>Z THEN DISP @ END ELSE M=N @ S=0 2 REPEAT @ S=S+MOD(M,10)^2 @ M=M DIV 10 @ UNTIL NOT M @ IF NOT PRIM(S) THEN DISP N; 3 END LOOP >RUN ? 1000 11 23 41 61 83 101 113 131 137 173 179 191 197 199 223 229 311 313 317 331 337 353 373 379 397 401 409 443 449 461 463 467 601 641 643 647 661 683 719 733 739 773 797 829 863 883 911 919 937 971 977 991 997 >RUN ? 10000 11 23 41 61 83 101 113 131 137 173 179 191 197 199 223 229 311 313 317 331 337 353 373 379 397 401 409 443 449 461 463 467 601 641 643 647 661 683 719 733 739 773 797 829 863 883 911 919 937 971 977 991 997 1013 1019 1031 1033 1091 1097 1103 1109 1163 1181 1277 1301 1303 1307 1361 1439 1451 1471 1493 1499 1613 1693 1697 16 99 1709 1741 1787 1811 1877 1901 1907 1949 2003 2029 2089 2111 2203 2221 2281 2333 2339 2393 2441 2557 2683 2777 2887 3011 3037 3079 3169 3253 3301 3307 3323 3329 3343 3347 3389 3433 3491 3583 3637 36 59 3673 3691 3701 3709 3853 3907 3923 4001 4049 4111 4139 4241 4337 4373 4391 4409 4421 4447 4481 4603 4649 4663 4733 4799 4919 4931 5059 5233 5303 5323 5477 5503 5527 5569 5639 5659 5693 5839 5857 60 43 6047 6089 6113 6131 6197 6199 6269 6311 6337 6353 6359 6373 6449 6599 6661 6719 6733 6791 6803 6823 6883 6917 6959 6971 6991 7013 7019 7039 7079 7103 7109 7127 7187 7307 7309 7411 7433 7457 7477 74 99 7547 7691 7703 7727 7817 7877 7901 7907 7949 8069 8111 8209 8221 8263 8287 8353 8539 8599 8609 8623 8803 8863 8887 8933 8999 9011 9091 9109 9323 9341 9413 9419 9431 9479 9491 9497 9613 9619 9631 97 49 9833 9859 9901 9907 9941 >RUN ? 100000 11 23 41 61 83 101 113 131 137 173 179 191 197 199 223 229 311 313 317 331 337 353 373 379 397 401 409 443 449 461 463 467 601 ... ... ... 98369 98411 98639 98909 98929 98963 99041 99089 99131 99133 99223 992 89 99377 99401 99559 99623 99643 99667 99719 99733 99809 99823 99829 99971 Quote:How many primes less than 1000 is this true for? This 110-byte, 2-liner variation will give the number of elements up to a given limit: 1 INPUT Z @ C=0 @ N=2 @ LOOP @ N=FPRIM(N+1) @ IF N>Z THEN DISP C @ END ELSE M=N @ S=0 2 REPEAT @ S=S+MOD(M,10)^2 @ M=M DIV 10 @ UNTIL NOT M @ C=C+NOT PRIM(S) @ END LOOP >RUN ? 1000 53 >RUN ? 10000 242 >RUN ? 100000 1818 >RUN ? 1000000 14731 > RUN ? 10000000 120495 >RUN ? 100000000 1021095 >RUN ? 1000000000 8736877 I've been unable to find the last three or four values above on the net so if someone can confirm their correctness I'd be grateful. Quote:What is the largest prime less than 100,000 where this is true? This 84-byte, 2-liner variation will do (and provide the prime sum as well): 1 INPUT N @ REPEAT @ N=FPRIM(N-1,2) @ M=N @ S=0 @ REPEAT 2 S=S+MOD(M,10)^2 @ M=M DIV 10 @ UNTIL NOT M @ UNTIL NOT PRIM(S) @ DISP N;S >RUN ? 1E5 99971 293 >RUN ? 1E9 999999667 607 >RUN ? 1E12 999999999767 863 Thanks for the interesting challenge and best regards. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
01-09-2018, 08:07 PM
Post: #16
|
|||
|
|||
challenge - prime numbers where sum of squared digits of prime number is also prime
.
Hi, Mike (01-08-2018 09:55 PM)Mike (Stgt) Wrote:(01-08-2018 07:43 PM)Valentin Albillo Wrote: This 109-byte, 3-liner will print all elements up to a given limit: Your N and/or Z variables are presently declared as COMPLEX. Execute a DESTROY ALL statement and rerun my program. Quote:IMHO, if N>Z we're done. Of course we are, that's why my routine next does a DISP to close the ongoing output line, then does an END to actually end execution. Regards. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
01-10-2018, 06:02 PM
Post: #17
|
|||
|
|||
Cucu
Hi again, Mike:
Quote:So I may not confirm your last value yet. Well, here's hoping you'll eventually succeed. In any case thanks a lot for trying. Regards. V. . All My Articles & other Materials here: Valentin Albillo's HP Collection |
|||
02-01-2018, 01:54 AM
(This post was last modified: 02-01-2018 02:18 AM by Dwight Sturrock.)
Post: #18
|
|||
|
|||
challenge - prime numbers where sum of squared digits of prime number is also prime
Program for the HP 12C
88 steps, uses 8 storage registers, must begin with the number 3 in the x register. Calculates the primes as requested up to 4 places- HP 12C. Program ran for 3min 35 secs to calculate up to 997. Will display the prime sum of the squares followed by the prime from which it is derived. [/php] STO 0 SQRT INTG STO 1 RCL 0 RCL 1 / FRAC X=0 GTO 19 1 STO -1 RCL 1 X<=Y GTO 17 GTO 05 RCL 0 GTO 23 2 STO +0 RCL 0 GTO 01 EE 3 / INTG STO 2 LST x X<>Y - EE 1 * INTG STO 3 LST x X<>Y - EE 1 * INTG STO 4 LST x X<>Y - EE 1 * INTG STO 5 RCL 2 //SQUARE EACH DIGIT AND SUM 2 Y^X RCL 3 2 Y^X + RCL 4 2 Y^X + RCL 5 2 Y^X + STO 6 //PRIME TEST SQRT INTG STO 1 RCL 6 RCL 1 / FRAC X=0 GTO 19 1 STO -1 RCL 1 X<=Y GTO 83 GTO 71 RCL 6 PSE RCL 0 PSE GTO 19 [php] |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)