标签:ios print 题意 += pow name 直接 log div
链接:http://acm.hdu.edu.cn/showproblem.php?pid=3117
题意:
#include <iostream> #include <cstdio> #include <cmath> using namespace std; typedef long long LL; int fib[40]; struct mat { int m[2][2]; }; int flag; int mod = 10000; void f() { fib[0] = 0; fib[1] = 1; for(int i = 2; ; i++) { fib[i] = fib[i-1] + fib[i-2]; if(fib[i] >= pow(10, 8)) { flag = i - 1; break; } } } int prev(LL n){ return pow( 10, (log10(1 / sqrt(5.0)) + n * log10((1 + sqrt(5.0)) / 2.0) - (int)(log10(1 / sqrt(5.0)) + n * log10((1 + sqrt(5.0)) / 2.0)) + 3)); } mat multiply(mat a, mat b) { mat c; for(int i = 0; i < 2; i++) { for(int j = 0; j < 2; j++) { c.m[i][j] = 0; for(int k = 0; k < 2; k++) { c.m[i][j] += (a.m[i][k] * b.m[k][j]) % mod; c.m[i][j] %= 10000; } } } return c; } mat p = {1, 1, 1, 0}; mat q = {1, 0, 0, 1}; mat quickPower(LL n) { mat m = p, b = q; while(n) { if(n & 1) { b = multiply(b, m); } n >>= 1; m = multiply(m, m); } return b; } int main() { LL n; f(); while (~scanf("%lld", &n)) { if(n <= flag) printf("%d\n", fib[n]); else { printf("%d...%04d\n", prev(n), quickPower(n).m[0][1]); } } return 0; }
标签:ios print 题意 += pow name 直接 log div
原文地址:http://www.cnblogs.com/stvn/p/7975976.html