第八届山东省赛题->Parity check

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


Example Output

看到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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值