Created
July 25, 2021 19:54
-
-
Save betaprojects/00368c04eca1812f4b990eab45ef670f to your computer and use it in GitHub Desktop.
Project Euler & HackerRank problem 44 solution: Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference is pentagonal and |Pk − Pj| is minimised - solved using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#HackerRank Project Euler 44 version | |
from math import sqrt | |
isp = lambda p: (sqrt(24*p+1)+1)/6 % 1 ==0 | |
ps = [(3*i*i - i) // 2 for i in range(1, 1000005)] | |
n,k = map(int, input().split()) | |
for n in range(k+1, n+1): | |
if isp(ps[n]+ps[n-k]) or isp(ps[n]-ps[n-k]): print (ps[n]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment