qdu Mathematics and Geometry(思维题)

来源:互联网 发布:人工智能理论 编辑:程序博客网 时间:2024/05/16 11:29


给你一个n,求方程 2x + y + 2z = n 解的个数,其中x, y, z, n 都是非负整数

第一行一个整数T(T<=1000),表示测试数据组数,接着T行,每行一个整数n(n<=1000000)

每组数据输出一行Case #x: ans 其中x表示样例组数,ans表示解的个数

 复制
3123
Case #1: 1Case #2: 3Case #3: 3

#include <iostream>#include <cstdio>using namespace std;int main(){int T, n, cnt = 0;long long  ans;cin >> T;while(T--){ans = 0;cin >> n;for(int y = 0; y <= n; y++){if((n - y)%2 == 0){ans += ((n - y)/2 + 1);}}printf("Case #%d: %lld\n", ++cnt, ans);}return 0;}



2 0
原创粉丝点击