#include<cstdio>
#include<iostream>
#include<cmath> using namespace std; int main()
{
int n;
scanf("%d",&n);
n--;
double q=sqrt(5.0);
int ans;
ans=((pow((+q)/2.0,n)/q-(pow((-q)/2.0,n)/n)));
cout<<ans<<endl;
return ;
}
洛谷P2626
题目背景
大家都知道,斐波那契数列是满足如下性质的一个数列: • f(1) = 1 • f(2) = 1 • f(n) = f(n-1) + f(n-2) (n ≥ 2 且 n 为整数)。
题目描述
请你求出第n个斐波那契数列的数mod(或%)2^31之后的值。并把它分解质因数。
输入输出格式
输入格式:
n
输出格式:
把第n个斐波那契数列的数分解质因数。
输入输出样例
输入样例#1:
5
输出样例#1:
5=5
输入样例#2:
6
输出样例#2:
8=2*2*2
说明
n<=48
上代码: #include <iostream>
#include <cstdio>
#include <cmath> #define Max 300 const long long Mod = pow (, ); void read (long long &now)
{
now = ;
char word = getchar ();
while (word < '' || word > '')
word = getchar ();
while (word >= '' && word <= '')
{
now = now * + word - '';
word = getchar ();
}
} long long fibonacii[Max]; int main (int argc, char *argv[])
{
register long long N;
fibonacii[] = ;
fibonacii[] = ;
read (N);
for (long long i = ; i <= N; i++)
fibonacii[i] = (fibonacii[i - ] + fibonacii[i - ]) % Mod;
long long Count = ;
long long number = ;
register long long now = fibonacii[N];
printf ("%lld=", now);
while (now != )
{
if (now % number)
number++;
else
{
Count++;
if (Count == )
printf ("%lld", number);
else
printf ("*%lld", number);
now /= number;
}
}
return ;
}