#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<string.h>
#define inf 0x3f3f3f
using namespace std;
int dp[1000000],n,a[1000000];
int main()
{
dp[0] = 7;
dp[1] = 11;
a[0] = 7;
a[1] = 11;
for(int i = 2; i <= 1000000 ; i++)
{
dp[i] = (dp[i-1]+dp[i-2])%3;
}
while(scanf("%d",&n) != EOF)
{
if(dp[n] == 0)printf("yes\n");
else printf("no\n");
}
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<string.h>
#define inf 0x3f3f3f
using namespace std;
int dp[1000000],n,a[1000000];
int main()
{
dp[0] = 7;
dp[1] = 11;
a[0] = 7;
a[1] = 11;
for(int i = 2; i <= 1000000 ; i++)
{
dp[i] = (dp[i-1]+dp[i-2])%3;
}
while(scanf("%d",&n) != EOF)
{
if(dp[n] == 0)printf("yes\n");
else printf("no\n");
}
}
开个数组DP预处理就OK了,如果中间一直加着走__int64也放不下,根据加法与整除的关系,所以可以每次都对3取模,只要为0就是可以被3整除的。