10674 arithmetic on

Original link: http://www.cnblogs.com/arcfat/archive/2012/11/10/2763577.html

10674 arithmetic on

Time limit: 1000MS Memory Limit: 65535K

Questions: Programming language title: Unlimited

 

Description

   Today is a special day, a once Singles, 2011.11.11, xym receive an envelope filled with gifts, XX is the book of a mm, which is two lollipops and a letter. 
The letter is a puzzle: 
    define if <x0, y0> and <x1, y1> meet x0-x1 = y0-y1, called for the two arithmetic right. 
mm question is asked <x, y> (0 < = x, y <= n) <0,0>, <0,1> ... <1,0>, <1,1> ... <2, 0>, 
<2,1> ... <the n-, 0> ... <the n-, 1> ... this (+ 1 n) ^ number of arithmetic presence of two ordered pair? 
    But xym since last night to listen to the girls in their class singing too late to bed, seriously affecting the state, and now he can only ask you scau hope for the future to help him solve this problem.

 

Input

A first line of input integer T (T <= 1000), represents a case. 
The following line T with T case, each case only one integer n (1 <= n <= 10 ^ 9), represents 0 <= x, y <= n; but since discovered when testing with scanf ( "% lld ", & n) have bug, so in order to fix the bug, please use long long read of students in reading before ascribed 0 to a variable, 
such as long long n = 0; scanf ( "% lld ", & n);

Output

Each case output a line indicating the number of arithmetic. This result may be large, only the final result% to 20,111,111.

 

Sample Input

2
2
100

 

Sample Output

5
338350

 

Hint

Be careful not to spill data, taking timely processing mode 







// Analysis:
In fact, this is the use of a matrix to solve the problem, put into x0-x1 = y0-y1 x0 -yo = x1-y1, and draw a matrix relationship very obvious
and C (2,2) + C (2,3 ) + C (2,4) + ... + C (2, n) = C (3, n + 1), and then rescued 2 * C (3, n + 1) + C (2, n + 1) is the required i.e.
// The following is the code AC
#include<stdio.h>

void process()
{
	long long n=0,sum,sum2,min;
	scanf("%lld",&n);
	
	if((n-1)%3==0)
	{
		min=(n-1)/3;
		sum2 = ((n+1)*n%20111111)*min;
	}
	else if(n%3==0)
	{
		min=n/3;
		sum2 = ((n+1)*(n-1)%20111111)*min;
	}
	else
	{
		min=(n+1)/3;
		sum2 = (n*(n-1)%20111111)*min;
	}
	
	sum=(n*(n+1))/2 + sum2;
	printf("%lld\n",sum%20111111);
}

int main()
{
	int T;
	scanf("%d",&T);
	while(T--) process();
	return 0;
}

Reproduced in: https: //www.cnblogs.com/arcfat/archive/2012/11/10/2763577.html

Guess you like

Origin blog.csdn.net/weixin_30462049/article/details/94789583
Recommended