I - Parity check
Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:524288KB 64bit IO Format:%lld & %llu
use MathJax to parse formulas
Description
Fascinated with the computer games, Gabriel even forgets to study. Now she needs to finish her homework, and there is an easy problem:
f(n)=
She is required to calculate f(n) mod 2 for each given n. Can you help her?
Input
Multiple test cases. Each test case is an integer n(0≤n≤) in a single line.
Output
For each test case, output the answer of f(n)mod2.
Sample Input
2
Sample Output
1
参考别人的:看到f(n)的表达式是不是立刻想到斐波那契数列了?如果是,那就错了!关键是f(n) mod 2 这意味着输出只有0和1(就是让你找规律的!) 而且看到n的范围的么,10的1000次方,这是什么概念... 所以,输入就要变一变啦,用字符串接受输入的数,字符串怎么参与计算呢?这就需要观察我们找的规律啦, 0110110110... 看出来没...(n mod 3) 所以,,现在关键是怎么把输入的字符串变n,既然是n mod 3,初中知识告诉我们... 一个数字能整除3,那数字的每一位上的数字之和也能整除3... 所以,问题解决啦,把字符串的每个字符变成数字然后相加,得到n,代码如下:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
//输入数字太大 处理为字符型
char c[1010];
int main()
{
while(scanf("%s",c)!=EOF)
{
int len=strlen(c);
int sum=0;
for(int i=0; i<len; i++)
{
sum+=c[i]-'0';
}
if(sum%3==0) printf("0\n");
else printf("1\n");
}
return 0;
}