HDU 1568
- - 我自己开始以为是数值范围是1到100000000.... 搞了半天才发现是斐波那契数列的项数1到100000000
坑爹、!!
不会,只能看网上大牛的题解、
具体解释请看:http://www.cnblogs.com/Yu2012/archive/2011/10/09/2199156.html
#include<iostream> #include<cmath> #include<cstdio> using namespace std; const double s = (sqrt(5.0)+1.0)/2; int main() { int n,i; double bit; int fac[21] = { 0 , 1 }; for(i = 2; i < 21; i++) fac[i] = fac[i-1] + fac [i-2]; while(cin >> n) { if(n <= 20) { cout << fac[n] << endl; continue; } else{ bit = -0.5*log(5.0)/log(10.0)+((double)n)*log(s)/log(10.0);//调用公式 bit = bit - floor(bit); //取小数部分└(^o^)┘ bit = pow(10.0,bit); while(bit < 1000) //要求四位,所以要将小数点右边的数移到左边直到符合要求 bit = 10.0 * bit; cout << (int)bit << endl; } } return 0; }