Given a really large number N, break it into 3 whole numbers such that they sum up to the original number and find the number of ways to do so. Since this number can be very large, return it modulo 10^{9}+7. 
 
Example 1:
Input:
N = 2
Output:
6
Explanation:
Possible ways to break the number:
0 + 0 + 2 = 2 
0 + 2 + 0 = 2
2 + 0 + 0 = 2
0 + 1 + 1 = 2
1 + 1 + 0 = 2
1 + 0 + 1 = 2
 
 
Example 2:
Input:
N = 3
Output:
10
Explanation:
Possible ways to break the number:
0+0+3 = 3
0+3+0 = 3
3+0+0 = 3
0+1+2 = 3
0+2+1 = 3
1+0+2 = 3
1+2+0 = 3
2+0+1 = 3
2+1+0 = 3
1+1+1 = 3
 
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function waysToBreakNumber() which takes an integer N and returns the possible ways to break the number in 3 parts.
 
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 10^{9}

Source: geeksforgeeks | Difficulty: EASY
Tags: Number theory

Mathematics

Starter code: #User function Template for python3





class Solution:

    def waysToBreakNumber(self, n):

        #code here

Solutions:
import math

class Solution:

	def waysToBreakNumber(self, n):
		return (n + 1) * (n + 2) // 2 % 1000000007


class Solution:

	def waysToBreakNumber(self, n):
		return (n * n + 3 * n + 2) // 2 % (10 ** 9 + 7)


class Solution:

	def waysToBreakNumber(self, n):
		return (n + 1) * (n + 2) // 2 % (10 ** 9 + 7)


class Solution:

	def waysToBreakNumber(self, n):
		return (n + 1) * (n + 2) // 2 % 1000000007


class Solution:

	def waysToBreakNumber(self, n):
		k = n + 1
		m = 10 ** 9 + 7
		return int(k * (k + 1) % m // 2) % m


class Solution:

	def waysToBreakNumber(self, N):
		return (N + 1) * (N + 2) // 2 % 1000000007


class Solution:

	def waysToBreakNumber(self, N):
		return (N + 1) * (N + 2) // 2 % (10 ** 9 + 7)


class Solution:

	def waysToBreakNumber(self, n):
		k = (n + 1) * (n + 2)
		tem = k // 2
		ans = tem % (10 ** 9 + 7)
		return ans


class Solution:

	def waysToBreakNumber(self, n):
		mod = 1000000007
		a = (n + 1) * (n + 2) // 2
		return a % mod


class Solution:

	def waysToBreakNumber(self, n):
		mod = 10 ** 9 + 7
		a = (n + 1) % mod
		b = (n + 2) % mod
		return a * b // 2 % mod


class Solution:
	count = 0

	def waysToBreakNumber(self, n):
		a = 1000000007
		count = n + 1
		b = count * (n + 2) % a
		b = b / 2
		b = b % a
		return int(b)


class Solution:

	def waysToBreakNumber(self, n):
		if n % 2 != 0:
			ans = (n + 2) % 1000000007 * ((n + 2) // 2 % 1000000007) % 1000000007
			return ans
		else:
			ans = (n + 1) % 1000000007 * ((n + 2) // 2 % 1000000007) % 1000000007
			return ans
		return (n * n + 3 * n + 2) // 2 % (10 ** 9 + 7)


class Solution:

	def waysToBreakNumber(self, n):
		if n % 2 != 0:
			a = (n + 2) % 1000000007
			b = (n + 2) // 2 % 1000000007
			ans = a * b % 1000000007
			return ans
		else:
			a = (n + 1) % 1000000007
			b = (n + 2) // 2 % 1000000007
			ans = a * b % 1000000007
			return ans


class Solution:

	def waysToBreakNumber(self, n):
		mod = 1000000007
		ans = (n + 1) % mod * ((n + 2) % mod) % mod / 2
		return int(ans)


class Solution:

	def waysToBreakNumber(self, n):
		if n != 0:
			res = (n + 1) * (n + 2) // 2
			if res >= 10 ** 9 + 7:
				return res % (10 ** 9 + 7)
			else:
				return res
		else:
			return 1


class Solution:

	def waysToBreakNumber(self, n):
		s = (n + 1) * (n + 2) % 1000000007
		s = s / 2
		return int(s)


class Solution:

	def waysToBreakNumber(self, n):
		mod = 1000000007
		summ = (n + 1) * (n + 2) // 2
		return summ % mod


class Solution:

	def waysToBreakNumber(self, n):
		return (n + 1) * (n + 2) // 2 % int(1000000000.0 + 7)


class Solution:

	def waysToBreakNumber(self, n):
		x = n + 1 % 1000000007
		y = n + 2 % 1000000007
		res = x * y % 1000000007
		return res // 2


class Solution:

	def waysToBreakNumber(self, n):
		total = int((n + 1) * (n + 2))
		return int(total % 1000000007 / 2)


class Solution:

	def waysToBreakNumber(self, n):
		m = 10 ** 9 + 7
		if n % 2:
			res = (n + 2) % m
			res *= int((n + 1) / 2) % m
		else:
			res = int((n + 2) / 2) % m
			res *= (n + 1) % m
		res %= m
		return res


class Solution:

	def waysToBreakNumber(self, n):
		m = 10 ** 9 + 7
		l = 3 * n + (n - 1) * (n - 2) // 2
		return l % m


class Solution:

	def waysToBreakNumber(self, n):
		c = 0
		c = (n * n + 3 * n + 2) // 2
		return c % int(1000000000.0 + 7)


class Solution:

	def waysToBreakNumber(self, n):
		m = 1000000000 + 7
		ans = (n + 1) * (n + 2) % m / 2 % m
		return int(ans)


class Solution:

	def waysToBreakNumber(self, n):
		c = (n + 1) * (n + 2) // 2
		return int(c % 1000000007)


MOD = 1000000007

def solve(n):
	m1 = (n + 1) % MOD
	m2 = (n + 2) % MOD
	ans = m1 * m2 // 2
	return ans % MOD

class Solution:

	def waysToBreakNumber(self, n):
		return solve(n)


import operator as op
from functools import reduce

class Solution:

	def waysToBreakNumber(self, N):

		def ncr(N, r):
			r = min(r, N - r)
			numer = reduce(op.mul, range(N, N - r, -1), 1) % 1000000007
			denom = reduce(op.mul, range(1, r + 1), 1) % 1000000007
			return numer // denom
		return ncr(N + 2, 2)