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