Post Reply 
challenge - prime numbers where sum of squared digits of prime number is also prime
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
 
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
challenge - prime numbers where sum of squared digits of prime number is also prime - Valentin Albillo - 01-08-2018 07:43 PM



User(s) browsing this thread: 1 Guest(s)