ZZULI 1869: Mathematics and Geometry【数学】

1869: Mathematics and Geometry

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 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;
 } 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值