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. TestNg-数据驱动-dataProvider

    参考https://blog.csdn.net/hjianhui24/article/details/50554828 之前的用例自己一笔一划写出来的,知道了数据驱动的概念之后,修改了一下用例. @D ...

  2. POJ 2449 Remmarguts' Date (第k短路径)

    Remmarguts' Date Time Limit: 4000MS   Memory Limit: 65536K Total Submissions:35025   Accepted: 9467 ...

  3. nginx安装配置: configure命令

    configure命令用来配置nginx编译环境. 该命令定义了系统各方面功能,包括允许nginx使用的连接处理方式. 其执行结果是生成一个Makefile文件. configure命令支持如下参数: ...

  4. group by、where、having

    where:是利用数据库本来存在的数据在查询,是在group by.having之前执行. group by:是将本来就有的数据按照条件进行分组. having:是将数据库没有的数据,可以理解为gro ...

  5. mysql数据库连接useSSL=true

    web应用中连接mysql数据库时控制台会出现这样的提示: Establishing SSL connection without server's identity verification is ...

  6. python正则提取关键字

    python使用正则表达式提取关键字 import sys reload(sys) sys.setdefaultencoding("utf-8") import re ss = & ...

  7. go vendor管理Golang项目依赖

    解决的问题 将源码拷贝到当前工程的vendor目录下,这样打包当前的工程代码到任意机器的$GOPATH/src下都可以通过编译. govendor 1.安装 go get -u -v github.c ...

  8. JavaSE_坚持读源码_ArrayList对象_Java1.7

    底层的数组对象 /** * The array buffer into which the elements of the ArrayList are stored. * The capacity o ...

  9. Flink HA 搭建坑

    目前网上能找到的做HA的教程基本都无法真正做到多机高可用,包括官方文档,经过很久的折腾,终于做到了多机高可用,希望其它人不再被坑. 集群模式安装 前提条件: 机器已经安装好Java环境 jobMana ...

  10. Docker笔记一:Docker介绍

    目录 什么是Docker? Docker的核心概念 Docker镜像命令 Docker容器命令 Docker实战 查看我的镜像 启动Redis Docker中国镜像加速 血与泪的教训 什么是Docke ...