Post Reply 
RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
06-01-2019, 03:07 AM (This post was last modified: 06-01-2019 03:11 AM by Gerson W. Barbosa.)
Post: #1
RPL exercise - Last Digits of Primes (HP 49G, G+, 50g)
Here are the first forty prime numbers greater than 5:

{  7  11  13  17  19  23  29  31  37  41 
  43  47  53  59  61  67  71  73  79  83 
  89  97 101 103 107 109 113 127 131 137 
 139 149 151 157 163 167 173 179 181 191 }

How many of them end with 1, 3, 7 and 9? Since these tend to be distributed evenly among the sample, we would expect finding about ten of each one. 
Indeed, upon careful counting we find 10, 10, 11 and 9, respectively.

Write a UserRPL program that given the number of the first prime numbers greater than 5 returns a list containing the number of occurrences, in order. 
For example, 

  40 --> {10 10 11 9}

 120 --> {29 31 32 28}

What is the result for 1000? 

Optionally, write a program that does the same for primes greater than 2 in base 8. In this case, the last digits are 1, 3, 5 and 7. 

  40 --> {7 12 11 10}

 120 --> {27 33 30 30}

1000 --> ?


Optimize programs for speed. Currently less than 160 seconds for 1000 primes (both programs, real HP 50g), but probably still not optimal.

Have fun!
  
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RPL exercise - Last Digits of Primes (HP 49G, G+, 50g) - Gerson W. Barbosa - 06-01-2019 03:07 AM



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