Fib[0]=0,Fib[1]=1,Fib[n]=Fib[n-1]+Fib[n-2] if n>1. 定义索函数Sor(n)=Fib[0]| Fib[1] |Fib[2]|…|Fib[n]. 给定整数n,要求计算Sor(n)%1,000,000,007(1e9+7).
Input 第1行:给出一个整数T,表示有T组数据。(1<=T<=10000) 第2行到T+1行,每行一个整数n。(0<=n<=10^10) Output 对于每个测试用例,输出结果占一行。 Input示例 2 1 2 Output示例 1 1
题解
代码
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<set> #include<ctime> #include<vector> #include<cmath> #include<algorithm> #include<map> #define mod 1000000007 #define ll long long #define inf 1e9 using namespace std; inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int gpow(ll k) { if (k==1) return 2; int t=gpow(k>>1); t=(ll)t*t%mod; if (k&1) t=t*2%mod; return t; } double f[95]; int main() { f[1]=1; for (int i=2;i<=90;i++) f[i]=f[i-1]+f[i-2]; int Case=read(); while (Case--) { int n=read(); if (n<=90) { int l=log(f[n])/log(2);int ans=gpow(l+1); printf("%d\n",ans-1); } else { ll l=n*log((1+sqrt(5))/2)/log(2)-log(sqrt(5))/log(2); int ans=gpow(l+1); printf("%d\n",ans-1); } } return 0; }