277 字
1 分钟
Shizuku-Hoshikawa-and-Farm-Legs

题面#

Nothing’s ever been the same since… that summer with her.

— Shizuku Hoshikawa

Kaori wants to spend the day with Shizuku! However, the zoo is closed, so they are visiting Farmer John’s farm instead.

At Farmer John’s farm, Shizuku counts nn legs. It is known that only chickens and cows live on the farm; a chicken has 22 legs, while a cow has 44.

Count how many different configurations of Farmer John’s farm are possible. Two configurations are considered different if they contain either a different number of chickens, a different number of cows, or both.

Note that Farmer John’s farm may contain zero chickens or zero cows.

Input

The first line contains a single integer tt (1t1001 \leq t \leq 100)  — the number of test cases.

The only line of each test case contains a single integer nn (1n1001\leq n \leq 100).

Output

For each test case, output a single integer, the number of different configurations of Farmer John’s farm that are possible.

思路#

根据题意列出方程: 2x+4y=n2x + 4y = n,设 xx 为鸡的数量,yy 为牛的数量

很明显的一个情况,nn 为奇数的时候,答案必定为 00

而如果为偶数,yy 可以从 00 取到 n4\frac{n}{4},所以方案数量为 n4+1\frac{n}{4} + 1

代码#

#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t --) {
int n;
cin >> n;
if (n % 2 != 0) cout << 0 << endl;
else cout << n / 4 + 1 << endl;
}
}
Shizuku-Hoshikawa-and-Farm-Legs
https://github.com/posts/shizuku-hoshikawa-and-farm-legs/
作者
FZSGBall
发布于
2026-05-26
许可协议
CC BY-NC-SA 4.0