題目描述
豆豆最近迷上了
輸入格式
第一行一個整數 T 代表提問次數。
接下來 T 行,每行一個數字 A 表示豆豆詢問你的數。
輸出格式
對於每次提問,如果這個數可以被分解成兩個
樣例數據
輸入
5
5
4
12
11
10
輸出
Yes
Yes
No
No
Yes
備註
【數據範圍】
對於 50% 的數據:A≤50;
對於 100% 的數據:T≤100;0≤A≤
分析:上次做過一道數學規律題立方數,就覺得這兩道題有異曲同工之妙啊!然後找了半天規律,沒找到……(斐波那契貌似也沒什麼公式啊orz)然後,我就無聊地打了一個算斐波那契數列的代碼:
發現斐波那契數列長這樣:
第45個數就超過
代碼
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<iomanip>
#include<queue>
#include<set>
using namespace std;
int getint()
{
int sum=0,f=1;
char ch;
for(ch=getchar();!isdigit(ch)&&ch!='-';ch=getchar());
if(ch=='-')
{
f=-1;
ch=getchar();
}
for(;isdigit(ch);ch=getchar())
sum=(sum<<3)+(sum<<1)+ch-48;
return sum*f;
}
const long long fib[46]={0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765,10946,17711,28657,46368,75025,121393,196418,317811,514229,832040,1346269,2178309,3524578,5702887,9227465,14930352,24157817,39088169,63245986,102334155,165580141,267914296,433494437,701408733,1134903170};
long long T,a;
bool bj;
int main()
{
freopen("fib.in","r",stdin);
freopen("fib.out","w",stdout);
T=getint();
while(T--)
{
bj=false,a=getint();
for(int i=0;i<=45;++i)
{
for(int j=0;j<=45;++j)
if(fib[i]*fib[j]==a)
{
bj=true;
break;
}
if(bj==true)
break;
}
if(bj==true)
{
cout<<"Yes"<<'\n';
}
else
cout<<"No"<<'\n';
}
return 0;
}
本題結。