http://acm.hust.edu.cn/vjudge/contest/view.action?cid=30506#problem/U

fib数列对2^m取模的循环节为3*(2^(m-1))

#include<map>
#include<set>
#include<list>
#include<cmath>
#include<ctime>
#include<deque>
#include<stack>
#include<bitset>
#include<cstdio>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<numeric>
#include<sstream>
#include<utility>
#include<iostream>
#include<algorithm>
#include<functional> using namespace std ;
const int maxn = 1000005 ; long long f[ 25 ][ maxn ] ; void Union()
{
for( int i = 1 ; i <= 20 ; ++i )
{
f[ i ][ 0 ] = 0 ;
f[ i ][ 1 ] = 1 ;
long long temp = 1 << i ;
for( long long j = 2 ; j < 3 * ( 1 << ( i - 1 ) ) ; ++j )
{
f[ i ][ j ] = ( f[ i ][ j - 1 ] % temp + f[ i ][ j - 2 ] % temp ) % temp ;
}
}
} int main()
{
Union() ;
int m , n ;
while( scanf( "%d%d" , &n , &m ) != EOF )
{
if( !m )
printf( "0\n" ) ;
else
printf( "%lld\n" , f[ m ][ n % ( 3 * ( 1 << ( m - 1 ) ) ) ] ) ;
}
return 0;
}

Modular Fibonacci的更多相关文章

  1. UVA - 10229 Modular Fibonacci 矩阵快速幂

                                 Modular Fibonacci The Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, 21, 3 ...

  2. UVA 10229 Modular Fibonacci

    斐波那契取MOD.利用矩阵快速幂取模 http://www.cnblogs.com/Commence/p/3976132.html 代码: #include <map> #include ...

  3. UVA题目分类

    题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics ...

  4. 算法与数据结构(九) 查找表的顺序查找、折半查找、插值查找以及Fibonacci查找

    今天这篇博客就聊聊几种常见的查找算法,当然本篇博客只是涉及了部分查找算法,接下来的几篇博客中都将会介绍关于查找的相关内容.本篇博客主要介绍查找表的顺序查找.折半查找.插值查找以及Fibonacci查找 ...

  5. #26 fibonacci seqs

    Difficulty: Easy Topic: Fibonacci seqs Write a function which returns the first X fibonacci numbers. ...

  6. 关于java的递归写法,经典的Fibonacci数的问题

    经典的Fibonacci数的问题 主要想展示一下迭代与递归,以及尾递归的三种写法,以及他们各自的时间性能. public class Fibonacci { /*迭代*/ public static ...

  7. 斐波拉契数列(Fibonacci) 的python实现方式

    第一种:利用for循环 利用for循环时,不涉及到函数,但是这种方法对我种小小白来说比较好理解,一涉及到函数就比较抽象了... >>> fibs = [0,1] >>&g ...

  8. fibonacci数列(五种)

    自己没动脑子,大部分内容转自:http://www.jb51.net/article/37286.htm 斐波拉契数列,看起来好像谁都会写,不过它写的方式却有好多种,不管用不用的上,先留下来再说. 1 ...

  9. POJ3070 Fibonacci[矩阵乘法]

    Fibonacci Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13677   Accepted: 9697 Descri ...

随机推荐

  1. hdu4722之简单数位dp

    Good Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tot ...

  2. asp.net后台对前台脚本的调用

    后台像前台输出要执行的脚本 Response.Write("<script>alert('内容')</script>"); asp.net后台调用前台js脚 ...

  3. Spring整合Hibernate的步骤

    为什么要整合Hibernate?1.使用Spring的IOC功能管理SessionFactory对象 LocalSessionFactoryBean2.使用Spring管理Session对象  Hib ...

  4. MSSQL - 备份和还原数据库

    SQL语句备份和还原数据库:http://blog.csdn.net/liuhelong/article/details/3335687 1.MSSQL - SqlServer:此数据库处于单用户模式 ...

  5. c语言,结构体

    数据类型分为4种, 简单数据类型,构造数据类型,指针数据类型,空类型. 结构体属于构造数据类型,用struct标识. 声明一个结构体: Typedef  struct和struct c c++ typ ...

  6. Java--Eclipse关联Java源码

    打开Eclipse,Window->Preferences->Java 点Edit按钮后弹出: 点Source Attachment后弹出: 选择Java安装路径下的src.zip文件即可 ...

  7. 【视频】零基础学Android开发:蓝牙聊天室APP(四)

    零基础学Android开发:蓝牙聊天室APP第四讲 4.1 ListView控件的使用 4.2 BaseAdapter具体解释 4.3 ListView分布与滚动事件 4.4 ListView事件监听 ...

  8. TCP与UDP在socket编程中的区别 (网络收集转载)

    http://blog.chinaunix.net/uid-26421509-id-3814684.html 一.TCP与UDP的区别 基于连接与无连接  对系统资源的要求(TCP较多,UDP少)  ...

  9. css 水平居中的办法

    <div style="width: 100%; text-align: center; margin: auto;"> <div style="dis ...

  10. MySQL filesort优化案例一则

    今天遇到一个filesort优化的案例,感觉不错,分享出来. MySQL中filesort是什么意思?官方手册定义: MySQL must do an extra pass to find out h ...