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. Linux(centos7)如何安装Zend Optimizer Zend Guard Loader

    下载地址:http://www.zend.com/en/products/loader/downloads#Linux 1.解压 wget http://downloads.zend.com/guar ...

  2. hystrix项目实战

    闲话少说: 总共分6步: (1)添加hystrix依赖以及监控的依赖 <dependency> <groupId>org.springframework.cloud</g ...

  3. tput

    tput : 改变终端显示特性,常见用法如下: tput lines : 显示终端的行数 tput cols : 显示终端的列数 tput cup line_number collum_number ...

  4. (最大连续和/最大子段和) P1115 最大子段和 洛谷

    题目描述 给出一段序列,选出其中连续且非空的一段使得这段和最大. 输入输出格式 输入格式: 第一行是一个正整数NN,表示了序列的长度. 第二行包含NN个绝对值不大于1000010000的整数A_iAi ...

  5. nginx根据cookie分流

    转载互联网 nginx根据cookie分流众所周知,nginx可以根据url path进行分流,殊不知对于cookie分流也很强大,同时这也是我上篇提到的小流量实验的基础. 二话不说,先看需求,两台服 ...

  6. ipv4转化为ipv6

    十進制轉換成十六進位 IPV6為十六進位,所以十進制轉換成十六進位192=c0 168=a8192.168.1.1 轉成 16 進制為 c0.a8.01.01可以使用 Windows 工程版或是程式設 ...

  7. Vue less使用scope时渗入修改子组件样式

    @deep: ~'>>>'; .wrap { @{deep} .component1 { width: 120px; } }

  8. Hbase_02、Hbase的常用的shell命令&Hbase的DDL操作&Hbase的DML操作(转)

    阅读目录 前言 一.hbase的shell操作 1.1启动hbase shell 1.2执行hbase shell的帮助文档 1.3退出hbase shell 1.4使用status命令查看hbase ...

  9. mysql导入导出sql文件,source导入速度慢的解决办法

    1.导出整个数据库mysqldump -u 用户名 -p 数据库名 > 导出的文件名mysqldump -u dbuser -p dbname > dbname.sql2.导出一个表mys ...

  10. row_number()over()使用

    语法: ROW_NUMBER ( ) OVER ( [ PARTITION BY value_expression , ... [ n ] ] order_by_clause ) 通过语法可以看出 o ...