MEI Maths Item of the Month August 2015 Prime Number Days

advertisement
MEI Maths Item of the Month
August 2015
Prime Number Days
The ISO standard for writing dates is YYYY-MM-DD: e.g. the 1st August 2015 is 2015-08-01.
The 21st August 2015 is a Prime Number Day because 20150821 is a prime number.
When will other Prime Number Days fall in 2015?
Will there ever be two consecutive Prime Number Days?
Solution
Using the following Python programs:
def isprime(n):
primetrue = 1
for i in range(2,int(n**0.5)+1):
if n%i==0:
primetrue=0
return primetrue
def primedays(y):
for m in range(1,13):
for d in range(1,32):
j = 10000*y+100*m+d
if isprime(j)==1:
print(j)
primedays(2015) returns 20150111, 20150131, 20150227, 20150303, 20150327,
20150411, 20150513, 20150821, 20151011, 20151031, 20151127, 20151221, 20151227
i.e. 11th Jan, 31st Jan, 27th Feb, 3rd Mar, 27th Mar, 11th Apr, 13th Apr, 21st Apr, 11th Oct,
31st Oct, 27th, Nov, 21st Dec and 27th Dec.
NB this program can return some false results for months that do not have 31 days.
def consec(y):
for j in range(2015,y+1):
for m in range(1,13):
s = 10000*j+100*m+31
t = 10000*j+100*(m+1)+1
if isprime(s)==1 and isprime(t)==1:
print([s,t])
consec(2020) returns [20170231, 20170301], [20170831, 20170901], [20180731,
20180801].
Ignoring the first pair gives 31st August and 1st September 2017 as the next pair of
consecutive prime number days with another pair on 31st July and 1st August 2018.
1 of 1
TB v1.0 © MEI
01/10/2015
Download