Parity check 斐波那契数列 取模 n(0≤n≤) in

I - Parity check

Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%lld & %llu

Submit Status

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

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Clark-dj

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值