project_euler.problem_044.sol1

Problem 44: https://projecteuler.net/problem=44

Pentagonal numbers are generated by the formula, Pn=n(3n-1)/2. The first ten pentagonal numbers are: 1, 5, 12, 22, 35, 51, 70, 92, 117, 145, … It can be seen that P4 + P7 = 22 + 70 = 92 = P8. However, their difference, 70 - 22 = 48, is not pentagonal.

Find the pair of pentagonal numbers, Pj and Pk, for which their sum and difference are pentagonal and D = |Pk - Pj| is minimised; what is the value of D?

Functions

is_pentagonal(→ bool)

Returns True if n is pentagonal, False otherwise.

solution(→ int)

Returns the minimum difference of two pentagonal numbers P1 and P2 such that

Module Contents

project_euler.problem_044.sol1.is_pentagonal(n: int) bool

Returns True if n is pentagonal, False otherwise. >>> is_pentagonal(330) True >>> is_pentagonal(7683) False >>> is_pentagonal(2380) True

project_euler.problem_044.sol1.solution(limit: int = 5000) int

Returns the minimum difference of two pentagonal numbers P1 and P2 such that P1 + P2 is pentagonal and P2 - P1 is pentagonal. >>> solution(5000) 5482660