1869: Mathematics and Geometry
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 204 Solved: 54
Submit Status Web Board
Description
给你一个n,求方程 2x + y + 2z = n 解的个数,其中x, y, z, n 都是非负整数
Input
第一行一个整数T(T<=1000),表示测试数据组数,接着T行,每行一个整数n(n<=1000000)
Output
每组数据输出一行Case #x: ans 其中x表示样例组数,ans表示解的个数
Sample Input
3
1
2
3
Sample Output
Case #1: 1
Case #2:
3
Case #3: 3
思路:2x+y+2z=2(x+z)+y=n,设t=2(x+z),那么t肯定是偶数,t的可能情况是0,2,4...等有n/2种,那么x+z的和就是0,1,2,..n/2,我们很容易知道答案是1+2+3+...+(n/2)+1.
AC-code:
#include<cstdio>
int main()
{
int T,i;
long long n;
scanf("%d",&T);
for(i=1;i<=T;i++)
{
scanf("%lld",&n);
if(n%2)
n=n/2*2;
printf("Case #%d: %lld\n",i,(2+n/2)*(n/2+1)/2);
}
return 0;
}