poj 1953(斐波那契通项公式解法)

#include<iostream>
#include<cmath> 
#include<cstdio>
using namespace std;
int main(){
    int t,i,kase;
    long long n;
    double ans;
    scanf("%d",&t);
    kase = 1;
    while(kase<=t){
        scanf("%lld",&n);
        printf("Scenario #%d:\n",kase++);
        ans = (pow((1+sqrt(5.0))/2,(double)n+2)-pow((1-sqrt(5.0))/2,(double)n+2))/sqrt(5.0);
        printf("%.0llf\n\n",ans);
    }
    return 0;
}

 

上一篇:poj 2136(水题)


下一篇:poj 1700(水题,找规律)