0% found this document useful (0 votes)
469 views1 page

Codechef

King Tle4Ever of Time Limit Exceeded holds an annual national Tic Tac Toe contest. This year there are n participants. The King wants to know the minimum and maximum possible sum of wi2, where wi is the number of matches won by participant i, from 1 to n. Given n, the program finds the minimum and maximum values mod 109+7 and prints them as "min max".
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
469 views1 page

Codechef

King Tle4Ever of Time Limit Exceeded holds an annual national Tic Tac Toe contest. This year there are n participants. The King wants to know the minimum and maximum possible sum of wi2, where wi is the number of matches won by participant i, from 1 to n. Given n, the program finds the minimum and maximum values mod 109+7 and prints them as "min max".
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

/**King Tle4Ever of Time Limit Exceeded is really fascinated about Tic Tac Toe.

He organizes a national level contest for Tic Tac Toe every year in Time Limit E
xceeded. (Though I agree you need to be really stupid to loose a game of Tic Tac
Toe but for the sake of question assume playing Tic Tac Toe for them is same as
playing Chess for us :P ).
Every year the contest has lots of participants. This year there are n participa
nts from all over the country. Seeing this huge participation he asks Moron a si
mple question.
Suppose participant pi wins wi matches. The king wants to know the sum of wi2 fr
om 1 to n. Now as you already know Moron is not good with maths, he asks you to
help him.
Given the value of n find the minimum and maximum value of sum of wi2 from 1 to
n. As values can be too large output the values mod 109+7.
[Input]
First line contains a single integer t denoting number of test cases.
Next t lines contains a single integer n denoting the number of participants.
[Output]
For each test case output the minimum and maximum value mod 109+7. Say minimum i
s minx and maximum is maxx than you should print "minx maxx".
[Constraints]
1<=t<=105
3<=n<=109
NOTE : n will be an odd integer
Sample Input (Plaintext Link)
2
3
5
Sample Output (Plaintext Link)
3 5
20 30
**/
k=1000000007
t=input()
while t>0:
max=min=0
t-=1
n=input()
for i in xrange(1,n):
max+=i**2
m=(n*(n-1))/2
min=((m/n)**2)*n
print min%k,max%k

You might also like