Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Count Consecutive Summers by Sillte
""" Policy
a + (a+1) + ... + (a + (a + t - 1)) = 1 / 2 * t * (2 * a + t - 1)
Seartch the number of a and t under the condition where a >= 1, t >= 1
and both of a and t are integer.
The calculation time is O(N).
I think efficient calculation of divisors are necessary to improve speed.
"""
def count_consecutive_summers(num):
def _condition(t):
if 2 * num % t != 0:
return False
u = 2 * num // t
a = (u - (t - 1)) / 2
return int(a) == a and 1 <= a
return sum(_condition(t) for t in range(1, 2 * num +1))
Dec. 9, 2018