Background: Violence is bound to exceed the data structure range, as the Fibonacci type sequence increases exponentially in the form of explosions. Therefore, the data found that the residual 30 does not affect the results.
Learning: 1. Number theory problems can write several sets of data to find the law, guess the conclusion.
My Code:
#include <stdio.h>int str[1000009] = {7,};int main () {int n;for (int i = 2; I <=1000000; i++) {Str[i] = (str[i -1] + str[i-2])% 30;} while (scanf ("%d", &n)! = EOF) {if (Str[n]% 3 = = 0) printf ("yes\n"); else printf ("no\n");} return 0;}
Some people also write the recursive {a1≡b1 (mod3) According to the nature of congruence, get A1+b1 (mod3)}:
Str[i] = str[i-1]%3+ str[i-2]%3;
OMS Solution:
Find the law, one at a time to find out the number of three f[0]~f[n:
1,2,0,2,2,1,0,1,1,2,0,2,2,1,0,1,1,2,0,2,2,1,0,1 .... Continuous circulation
Our goal is to find the relationship between 0 and N after the remainder, except the first, 0 and 0 are three numbers, so easy to get as long as n%4==2, then f[n]=0.
HDU 1021 Fibonacci 2, finding the law