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 思路:
  因为是或运算,那么将其Sor(n)转化为二进制,每一位上的值均应该为1,那么我们只需要求出二进制的位长,便可以求得Sor(n)。
  对于斐波那契数列数列有:

   

  此时求其以2为底的对数,无法去掉n次幂,很难进行进一步化简,我们继续考虑:

  当n趋近于无穷大时:

  的值趋近于0,

  即此时求出Sor(n)转化为二进制时的长度为:

log2(15√(1+5√2)n)
log2(15√(1+5√2)n)

   

  进行化简得:

  

  可以O(1)求出Sor(n)的位长len,通过快速幂求出 2^(len+1)的值后减去一得到Sor(n)的数值。

  蛮有意思的一道题目。

  

#include <stdio.h>
#include <math.h>
#define MAXSIZE 90
#define INF 0x3f3f3f3f
#define LL long long const int mod = 1e9+; double f[MAXSIZE]; LL Pow(LL a,LL n)
{
LL ans = ;
while(n)
{
if(n & )
{
ans = (ans*a)%mod;
}
a = (a*a)%mod;
n >>= ;
}
return ans%mod;
} LL Solve(LL n)
{
LL ans,len;
if(n < MAXSIZE)
{
len = log(f[n])/log(2.0);
}
else
len = n*log((+sqrt(5.0))/2.0)/log(2.0) - log(sqrt(5.0))/log(2.0);
ans = Pow(,len+);
return ans;
} int main()
{
f[] = ;
f[] = ;
f[] = ;
for(int i=;i<MAXSIZE;i++)
{
f[i] = f[i-] + f[i-];
}
int T;
LL n;
scanf("%d",&T);
while(T--)
{
scanf("%lld",&n);
if(n==)
{
printf("0\n");
continue;
}
LL ans = Solve(n);
printf("%lld\n",ans-);
}
return ;
}

  

    

  



												

51nod 1379 索函数的更多相关文章

  1. 51nod1379 索函数

    果断打表找规律.然后看得出来是2^k-1之后又不知道怎么求出k有什么卵用... http://blog.csdn.net/guhaiteng/article/details/52094210 %%%% ...

  2. 51nod 1244 莫比乌斯函数之和

    题目链接:51nod 1244 莫比乌斯函数之和 题解参考syh学长的博客:http://www.cnblogs.com/AOQNRMGYXLMV/p/4932537.html %%% 关于这一类求积 ...

  3. 51nod 1240 莫比乌斯函数

    题目链接:51nod 1240 莫比乌斯函数 莫比乌斯函数学习参考博客:http://www.cnblogs.com/Milkor/p/4464515.html #include<cstdio& ...

  4. 51nod 1244 莫比乌斯函数之和 【杜教筛】

    51nod 1244 莫比乌斯函数之和 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用μ(n)(miu(n))作为莫比乌斯函数的记号.具体定义如下: 如果一个数包含 ...

  5. [51Nod 1244] - 莫比乌斯函数之和 & [51Nod 1239] - 欧拉函数之和 (杜教筛板题)

    [51Nod 1244] - 莫比乌斯函数之和 求∑i=1Nμ(i)\sum_{i=1}^Nμ(i)∑i=1N​μ(i) 开推 ∑d∣nμ(d)=[n==1]\sum_{d|n}\mu(d)=[n== ...

  6. 51nod 1244 莫比乌斯函数之和(杜教筛)

    [题目链接] http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1244 [题目大意] 计算莫比乌斯函数的区段和 [题解] 利 ...

  7. 51nod 1240 莫比乌斯函数【数论+莫比乌斯函数】

    1240 莫比乌斯函数 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题  收藏  关注 莫比乌斯函数,由德国数学家和天文学家莫比乌斯提出.梅滕斯(Mertens)首先使用 ...

  8. 51Nod.1244.莫比乌斯函数之和(杜教筛)

    题目链接 map: //杜教筛 #include<map> #include<cstdio> typedef long long LL; const int N=5e6; in ...

  9. 51nod 1244 莫比乌斯函数之和 【莫比乌斯函数+杜教筛】

    和bzoj 3944比较像,但是时间卡的更死 设\( f(n)=\sum_{d|n}\mu(d) g(n)=\sum_{i=1}^{n}f(i) s(n)=\sum_{i=1}^{n}\mu(i) \ ...

随机推荐

  1. Httpclient超时timeout设置

    一:连接超时:connectionTimeout 1:指的是连接一个url的连接等待时间. 二:读取数据超时:soTimeout 1:指的是连接上一个url,获取response的返回等待时间. Fo ...

  2. https服务器配置部署

    现在很多网站都要是https,包括我之前做的微信小程序都是需要使用https传输的,特将之前学习的记录下,以防忘记 一. 1.HTTPS简介 HTTPS其实是有两部分组成:HTTP + SSL / T ...

  3. CentOS 安装最新版本 Git

    查看默认 yum 源的 git版本 # 安装 yum install -y git # 查看版本 git version # git version 1.8.3.1 参看官网,CentOS 安装新版本 ...

  4. springboot下整合redis使用redisTemplate模板

    pom <!-- 引入 redis 依赖 --> <dependency> <groupId>org.springframework.boot</groupI ...

  5. 6.适配器模式(Adapter Pattern)

    适配(转换)的概念无处不在......适配,即在不改变原有实现的基础上,将原先不兼容的接口转换为兼容的接口.例如:二转换为三箱插头,将高电压转换为低电压等.    动机(Motivate):    在 ...

  6. 3.建造者模式(Builder)

    Builder模式的缘起:    假设创建游戏中的一个房屋House设施,该房屋的构建由几部分组成,且各个部分富于变化.如果使用最直观的设计方法,每一个房屋部分的变化,都将导致房屋构建的重新修正... ...

  7. html页面导出为excel表格

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  8. rpmbuild打包php

    安装php依赖库 mkdir -pv ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} php有一个依赖库,在yum源于epel源中都没有需要自己打包libico ...

  9. [leetcode-118]Pascal's triangle 杨辉三角

    Pascal's triangle (1过) Given numRows, generate the first numRows of Pascal's triangle. For example, ...

  10. ACM-ICPC 2018 南京赛区网络预赛 G Lpl and Energy-saving Lamps(模拟+线段树)

    https://nanti.jisuanke.com/t/30996 题意 每天增加m个灯泡,n个房间,能一次性换就换,模拟换灯泡过程.询问第几天的状态 分析 离线做,按题意模拟.比赛时线段树写挫了. ...