Skip to content

Commit 42344c4

Browse files
authored
Update the-number-of-ways-to-make-the-sum.py
1 parent aad09d5 commit 42344c4

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Python/the-number-of-ways-to-make-the-sum.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def numberOfWays(self, n):
2626
def count_1_2_6(n):
2727
# sum((n-6*i)//2+1 for i in xrange((n//6)+1))
2828
# = sum(((n//2)+1)-3*i for i in xrange((n//6)+1))
29-
return ((n//2+1)*((n//6)-0+1)-3*((n//6)+0)*((n//6)-0+1)//2)%MOD
29+
return (n//2+1)*((n//6)-0+1)-3*((n//6)+0)*((n//6)-0+1)//2
3030

3131
return reduce(lambda x, y: (x+count_1_2_6(n-4*y))%MOD, (i for i in xrange(min(n//4, 2)+1)), 0)
3232

@@ -45,7 +45,7 @@ def count_1_2(n):
4545
return n//2+1
4646

4747
def count_1_2_6(n):
48-
return reduce(lambda x, y: (x+count_1_2(n-6*y))%MOD, (i for i in xrange((n//6)+1)), 0)
48+
return sum(count_1_2(n-6*i) for i in xrange((n//6)+1))
4949

5050
return reduce(lambda x, y: (x+count_1_2_6(n-4*y))%MOD, (i for i in xrange(min(n//4, 2)+1)), 0)
5151

@@ -64,5 +64,5 @@ def numberOfWays(self, n):
6464
dp[0] = 1
6565
for i in (1, 2, 6):
6666
for j in xrange(i, n+1):
67-
dp[j] = (dp[j]+dp[j-i])%MOD
67+
dp[j] += dp[j-i]
6868
return reduce(lambda x, y: (x+dp[n-4*y])%MOD, (i for i in xrange(min(n//4, 2)+1)), 0)

0 commit comments

Comments
 (0)