Problem 52990. Easy Sequences 46: Semi-prime Leap Year Pairs
A semi-prime is a positive integer that has only 2 and exactly 2 prime factors. Here is a list of the first few semi-primes:
.
We define a Semi-prime Leap Year Pair as a pair of years, whose difference is a semi-prime number and at least one year in the pair is a leap year. Examples of semi-prime leap year pairs are:
,
, and
.
Given a year number y, write a program that counts the number of semi-prime leap year pairs between year
and y, inclusive.
NOTE: Leap years are defined as those years that are divisible by 4, except for those that ends in
, in which case a year is a leap year only if it is divisible by
. This rule was introduced only starting
. Before
, the rule is much simpler, namely, except for
, all years that are multiples of 4, are leap years. Please apply the appropriate rule for each year. Also, please assume that there will not be any more leap year definition changes in the future.
EXAMPLE: For
, the semi-primes are:
, and the leap years are:
. Therefore the semi-prime leap year pairs for this case are as follows:
Therefore, in this case the function should return:
pairs.
Solution Stats
Problem Comments
-
1 Comment
GeeTwo
on 7 Jan 2023
I scored it medium because even though it took way more time than it should have, I didn't do any literature searches.
OBTW, the drop from my first to second solution was due to borrowing @Tim 's semiprime generator, which I shall likely also use on ES 47, Boxes with Prime Edges.
Solution Comments
Show commentsProblem Recent Solvers2
Suggested Problems
-
15693 Solvers
-
96 Solvers
-
1949 Solvers
-
Polar Form Complex Number Entry
46 Solvers
-
10 Solvers
More from this Author116
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!