Problem 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.
Example Input
2
Example 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 <stdio.h>
#include <string.h>
#define N 1010
int main()
{
char s[N];
int i,sum;
while(~scanf("%s",s))
{
sum=0;
for(i=0;i<strlen(s);i++)
sum+=s[i]-'0';
if(sum%3==2||sum%3==1)
printf("1\n");
else
printf("0\n");
}
return 0;
}