File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -10,8 +10,16 @@ def consecutiveNumbersSum(self, N):
10
10
# x + x+1 + x+2 + ... + x+l-1 = N = 2^k * M, where k >= 0 and M is odd
11
11
# => l*x + (l-1)*l/2 = 2^k * M
12
12
# => x = (2^k * M - (l-1)*l/2) / l = 2^k * M/l - (l-1)/2 is a positive integer
13
- # => l could be 2^(k+1) or any odd factor of M (only one of 2^(k+1) and M is possible)
13
+ # => l could be 2^(k+1) or any odd factor of M (only one of 2^(k+1) and M must be possible, proof as follows )
14
14
# s.t. x = 2^k * M/l - (l-1)/2 is a positive integer, and also unique
15
+ #
16
+ # proof:
17
+ # if l = 2^(k+1) is impossible
18
+ # <=> 2^k * M/(2^(k+1)) - (2^(k+1)-1)/2 <= 0
19
+ # <=> M - 2^(k+1) <= -1
20
+ # <=> 2^(k+1) >= M+1
21
+ # <=> 2^k * M/M - (M-1)/2 >= 1, l = M is possible
22
+ #
15
23
# => the answer is the number of all odd factors of M
16
24
# if prime factorization of N is 2^k * p1^a * p2^b * ..
17
25
# => answer is the number of all odd factors = (a+1) * (b+1) * ...
You can’t perform that action at this time.
0 commit comments