Skip to main content

Posts

Hackerrank - Summing the N series Solution

You are given a sequence whose   term is You have to evaluate the series Find  . Input Format The first line of input contains  , the number of test cases. Each test case consists of one line containing a single integer  . Constraints Output Format For each test case, print the required answer in a line. Sample Input 0 2 2 1 Sample Output 0 4 1 Explanation 0 Case 1: We have  Case 2: We have 1 = 1 Solution in python import os import sys for i in range(int(input())):     n = int(input())     print((n ** 2) % (10**9+7))
Recent posts

Hackerrank - Cutting Paper Squares Solution

Mary has an   piece of paper that she wants to cut into   pieces according to the following rules: She can only cut  one piece of paper at a time , meaning she  cannot  fold the paper or layer already-cut pieces on top of one another. Each cut is a straight line from one side of the paper to the other side of the paper. For example, the diagram below depicts the three possible ways to cut a   piece of paper: Given   and  , find and print the minimum number of cuts Mary must make to cut the paper into   squares that are   unit in size. Input Format A single line of two space-separated integers denoting the respective values of   and  . Constraints Output Format Print a long integer denoting the minimum number of cuts needed to cut the entire paper into   squares. Sample Input 3 1 Sample Output 2 Explanation Mary first cuts the   piece of paper into a   piece and a...