题面
Right now, the largest social experiment in the history of Codeforces is taking place, involving people. They are required to form teams of people, after which each team chooses one of two civilizations to participate in the social experiment.
The organizers of this social experiment want to know what the possible difference in the number of people in the civilizations could be. Find the minimum possible difference.
Input
Each test consists of several test cases. The first line contains a single integer — the number of test cases. The following lines describe the test cases.
In the only line of each test case, there is an integer — the number of people participating in the social experiment .
Output
For each number , output the minimum possible difference between the number of people in the civilizations.
思路
题目本质要求的就是两种文明选择人数的最小差值
而成组方面,要么是2人成组,要么是3人成组
所以注意到,有两种特判案例:
- 答案就是2
- 答案就是3
当 时:
如果 为偶数,那么两种文明平分队伍,都是2人队,答案为0
如果 为奇数,那么两种文明的人数最小差必定是1
代码
#include <bits/stdc++.h>
using namespace std;
int main() { int t; cin >> t; while (t --) { int n; cin >> n; if (n == 2 || n == 3) cout << n << endl; else { cout << n % 2 << endl; } }}