Fibonacci Game - Basics

Fibonacci game

There is a pile of stones with a number of n (n>=2) . Both sides of the game take turns to take stones. The rules are as follows:

1) The first mover cannot take all the stones at the first time, at least one stone is taken ;

2) The number of stones that can be taken each time after that is at least 1 , and at most 2 times the number of stones the opponent just took .

It is agreed that the person who takes the last stone will be the winner.

Conclusion: When n is a Fibonacci number, you must lose.

f[i]1,2,3,5,8,13,21,34,55,89……

nyoj358 take stones (5)

Time Limit: 1000  ms | Memory Limit: 65535  KB

Difficulty: 4

describe

himdd wanted to play a game recently, so he found acmj to play with him, the game is like this: there is a pile of stones , two people take turns to take a certain amount of stones from it , and the person who takes all the stones at the end is the winner , but the following rules must be followed : 1. The first time you can't take it all , take at least 1 piece .

2. From the second time onwards , the number of stones each player takes is at least 1, and at most twice the number of stones the opponent just took.

himdd wants to know in advance if he will win, can you help him? (every time himdd goes first)

enter

There are multiple sets of test data, each set has an integer n (2<=n<2^64);

output

himdd will win and output Yes, otherwise, output No;

sample input

2

5

6

Sample output

No

No

Yes

#include<stdio.h>
long long a[105]={0,1};
intmain()
{
	long long n;
	for(int i=2;i<100;i++)
	a[i]=a[i-1]+a[i-2];
	while(~scanf("%lld",&n))
	{
		int f=0;
		for(int i=1;i<100;i++)
		{
			if(a[i]==n)
			{
				f=1;break;
			}
			if(a[i]>n)
			break;
		}
		if(f)
		printf("No\n");
		else
		printf("Yes\n");
	}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325555705&siteId=291194637