斐波那契数列模$10^m$的循环节为$6\times10^m$,于是从低位到高位dfs即可。

#include<cstdio>
#include<cstring>
#define N 20
typedef long long ll;
typedef unsigned long long ull;
int n,i,flag;char a[N];ll mo[N],b[N];ull ans;
inline ull mul(ull a,ull b,ull P){ull t=0;for(;b;b>>=1,a=(a+a)%P)if(b&1)t=(t+a)%P;return t;}
void cal(ll n,ll&x,ll&y,ll P){
if(!n){x=0,y=1;return;}
if(n==1){x=y=1;return;}
if(n&1){
cal(n-1,y,x,P);
y=(1ULL*y+x)%P;
return;
}
ll a,b;
cal(n>>1,a,b,P);
x=(mul(a,b,P)+mul(a,b<a?b-a+P:b-a,P))%P;
y=(mul(a,a,P)+mul(b,b,P))%P;
}
inline ll fib(ll n,ll P){ll x,y;cal(n,x,y,P);return x;}
void dfs(int n,ll t,ll T){
if(flag)return;
if(fib(t,mo[n])!=b[n])return;
if(n==1){flag=1,ans=6000000000000000000ULL+t;return;}
for(int i=0;i<10;i++)dfs(n-1,(1ULL*t+T*i)%(T*10),T*10);
}
int main(){
scanf("%s",a+1),n=strlen(a+1);
for(mo[i=n]=1;i;i--,mo[i]=mo[i+1]*10)b[i]=mo[i]*(a[i]-'0')+b[i+1];
for(i=1;i<=n;i++)mo[i]*=10;
for(i=0;i<60;i++)dfs(n,i,60);
if(flag)printf("%llu",ans);else puts("NIE");
return 0;
}

  

BZOJ4294 : [PA2015]Fibonacci的更多相关文章

  1. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

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

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

  3. #26 fibonacci seqs

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

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

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

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

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

  6. fibonacci数列(五种)

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

  7. POJ3070 Fibonacci[矩阵乘法]

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

  8. Fibonacci 数列算法分析

    /************************************************* * Fibonacci 数列算法分析 ****************************** ...

  9. 算法系列:Fibonacci

    Copyright © 1900-2016, NORYES, All Rights Reserved. http://www.cnblogs.com/noryes/ 欢迎转载,请保留此版权声明. -- ...

随机推荐

  1. How To Install Linux, Nginx, MySQL, PHP (LEMP) Stack on Debian 7

    https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on- ...

  2. python网络编程之最简单的单工通信

    tcp_server.py from socket import * server = socket(AF_INET, SOCK_STREAM) server.bind(('',12345)) ser ...

  3. VS2008+Qt+助手 智能提示不显示、Qt关键字不高亮的解决办法【已解决】

    笔者使用的开发环境是VS2008+Qt4.8.5+VAssistX,有时候会出现代码关键字不能高亮显示,并且助手的智能提示不显示.问题如下 解决的办法是在助手的选项中设置其搜索路径,助手的设置通过VS ...

  4. Sort List

    采用归并排序,通过定义快.慢两个指针来找到中点,再采用之前的排序算法进行归并. ListNode *listSort(ListNode *head) { //定义快慢指针,找到链表中心 ListNod ...

  5. MySQL Profiling 的使用

    MySQL Profiling 的使用 在本章第一节中我们还提到过通过 Query Profiler 来定位一条 Query 的性能瓶颈,这里我们再详细介绍一下 Profiling 的用途及使用方法. ...

  6. PhpStorm主题

    图的github仓库有很多编辑器的主题,jetbrains目录下都是PhpStorm支持的主题 1.到http://daylerees.github.io/预览各个主题的风格,找到自己喜欢的: 2.在 ...

  7. datetime中strftime和strptime用法

    from datetime import * format = "%Y-%m-%d %H:%M:%S" a=datetime.now() day=a.day b=a.replace ...

  8. 设置windows网络连接别名和linux网络连接别名

    windows网络连接别名 C:\Windows\System32\drivers\etc目录下的hosts文件中添加 127.0.0.1 localhost 192.168.1.100 proxy. ...

  9. Android的Observable和iOS的NotificationCenter

    使用起来很类似,参看以下网址http://stackoverflow.com/questions/10327200/equivalent-of-ios-nsnotificationcenter-in- ...

  10. Java for LeetCode 188 Best Time to Buy and Sell Stock IV【HARD】

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...