标签:fibonacii 输入输出 void number return mat pow str lld
#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((1+q)/2.0,n)/q-(pow((1-q)/2.0,n)/n))); cout<<ans<<endl; return 0; }
大家都知道,斐波那契数列是满足如下性质的一个数列: ? f(1) = 1 ? f(2) = 1 ? f(n) = f(n-1) + f(n-2) (n ≥ 2 且 n 为整数)。
请你求出第n个斐波那契数列的数mod(或%)2^31之后的值。并把它分解质因数。
n
输出格式:
把第n个斐波那契数列的数分解质因数。
5
5=5
6
8=2*2*2
n<=48
#include <iostream> #include <cstdio> #include <cmath> #define Max 300 const long long Mod = pow (2, 31); void read (long long &now) { now = 0; char word = getchar (); while (word < ‘0‘ || word > ‘9‘) word = getchar (); while (word >= ‘0‘ && word <= ‘9‘) { now = now * 10 + word - ‘0‘; word = getchar (); } } long long fibonacii[Max]; int main (int argc, char *argv[]) { register long long N; fibonacii[1] = 1; fibonacii[2] = 1; read (N); for (long long i = 3; i <= N; i++) fibonacii[i] = (fibonacii[i - 1] + fibonacii[i - 2]) % Mod; long long Count = 0; long long number = 2; register long long now = fibonacii[N]; printf ("%lld=", now); while (now != 1) { if (now % number) number++; else { Count++; if (Count == 1) printf ("%lld", number); else printf ("*%lld", number); now /= number; } } return 0; }
标签:fibonacii 输入输出 void number return mat pow str lld
原文地址:http://www.cnblogs.com/zxqxwnngztxx/p/6675572.html