You will be given an integer n, your task is to return the sum of all natural number less than or equal to n.
As the answer could be very large, return answer modulo 10^{9}+7.
Example 1:
Input:
n = 6
Output:
21
Explanation:
1+2+3+4+5+6 = 21
Example 2:
Input:
n = 4
Output:
10
Explanation:
1+2+3+4 = 10
Your Task:
You don't need to read input or print anything. Your task is to complete the function sumOfNaturals() which takes a single integer n as input and returns sum of all numbers x upto n, i.e., 1 <= x <= n.
Expected Time Complexity: O(1)
Expected Auxiliary Space: O(1)
Constraints:
0 <= n <= 10^{7}

Source: geeksforgeeks | Difficulty: EASY
Tags: Mathematics

Starter code: #User function Template for python3



class Solution:

    def sumOfNaturals(self, n):

        # code here 

Solutions:
class Solution:

	def revCoding(self, n, m):
		sum = n * (n + 1) / 2
		if m == sum:
			return 1
		else:
			return 0


class Solution:

	def revCoding(self, n, m):
		summ = n * (n + 1) / 2
		if summ == m:
			return 1
		return 0


import math

class Solution:

	def revCoding(self, n, m):
		return int(n * (n + 1) / 2 == m)


class Solution:

	def revCoding(self, n: int, m: int) -> int:
		if self._sum(n) == m:
			return 1
		else:
			return 0

	@staticmethod
	def _sum(num: int) -> int:
		return num * (num + 1) // 2


class Solution:

	def revCoding(self, n, m):
		return (n * (n + 1) / 2 == m) & 1


class Solution:

	def revCoding(self, n, m):
		x = n / 2
		y = n * x + x
		if y == m:
			return 1
		else:
			return 0


class Solution:

	def revCoding(self, n, m):
		return int(n * (n / 2) + n / 2 == m)


class Solution:

	def revCoding(self, n, m):
		s = int(n * (n + 1) / 2)
		if s == m:
			return 1
		else:
			return 0


class Solution:

	def revCoding(self, n, m):
		if m == n * (n + 1) * 0.5:
			return 1
		else:
			return 0


class Solution:

	def revCoding(self, n, m):
		if n * (n + 1) // 2 == m:
			return 1
		return 0
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		ob = Solution()
		print(ob.revCoding(n, m))