问题 I: I Parity check
时间限制: 3 Sec 内存限制: 128 MB提交: 2 解决: 1
[提交][状态][讨论版]
题目描述
Fascinated with the computer games, Gabriel even forgets to study. Now she needs to finish her homework, and there is an easy problem:
She is required to calculate f(n) mod 2 for each given n. Can you help her?
输入
Multiple test cases. Each test case is an integer in a single line.
输出
For each test case, output the answer of f(n)mod2.
样例输入
2
样例输出
1
提示
分析:刚开始被队友看成大数除法,后来发现就是小学数学。。。。
结果对二取余,就是判断他的奇偶性,找到规律后发现就是判断一个数是不是3的倍数,小学数学各项相加判断是不是3的倍数就可以了。
#include <bits/stdc++.h>using namespace std;string a;int main()
{while(cin>>a){long long ans=0;for(int i=0;i<a.length();i++){ans+=a[i];}if(ans % 3==0){puts("0");}else{puts("1");}}return 0;
}