The nth term of the pentagonal sequence is defined as:
Pn = n*(3*n - 1)/2
Find a pair of two pentagonal numbers
Pk, such that:
Pk + Pj = S is a pentagonal number Pk - Pj = D is a pentagonal number and is minimum too.
What is the value of
We will run two loops:
Then, we will calculate and check if
S are pentagonal.
To check this, we will inverse the pentagonal function.
The moment we get a pair for which
S are pentagonal, we’ll break the loop and return
This is because the first pentagonal
D is also the minimum one.
""" Coded by - Armaan Nougai """ from math import sqrt def is_pentagonal(n): return (1+sqrt(1+24*n))%6==0 i=0 while True: i+=1 k = i*(3*i-1)//2 for v in range(1,i): j = v*(3*v-1)//2 if is_pentagonal(k-j) and is_pentagonal(k+j) : print(k-j) break else: continue break
Why is the first value of
D(i.e., 5482660) the minimum possible value of
On analyzing the pentagonal sequence:
P(n)-P(n-1) < P(n+1)-P(n) < P(n+2)-P(n+1) ...
This means the difference between adjacent terms is increasing.
And also, for the nth term, the minimum
D, even without the condition, will be:
Now, after getting the first value of
D, we will continue the search for the lesser value of
D until we find an adjacent pair that satisfies the condition and whose
D is greater than the first value of
This is because, after this point, the
D of every pair will be greater than the first value of
View all Courses