Triangular Pattern Row Sums

Company: Infoedge

Difficulty: easy

Problem Statement

Triangular Pattern Row Sums The positive integers 1, 2, 3, 4, ... are written down one after another into a triangular pattern. Row 1 receives the first 1 integer, row 2 receives the next 2 integers, row 3 receives the next 3 integers, and in general row k receives the next k integers, continuing forever. The first few rows therefore look like this: row 1: 1 row 2: 2 3 row 3: 4 5 6 row 4: 7 8 9 10 row 5: 11 12 13 14 15 row 6: 16 17 18 19 20 21 You are given N independent queries. The i -th query gives a row number R[i] , and you must report the sum of all the integers written in that row, taken modulo 10^9 + 7 . Input Format The first line contains a single integer N , the number of queries. Each of the next N lines contains a single integer R[i] , the row number asked about by the i -th query. (inferred — the on-screen prose said "the second line contains N space-separated integers", but both of the source's own samples, and the pre-given driver code that reads one value per getline ,