【2012-12】【斐波那契循环节】Evil Teacher
2015-01-11 20:55
323 查看
定理:
设P(m)为斐波那契模m的循环节
若m=p1^t1*p2^t2...
则P(m)=lcm(P(p1^t1),P(p2^t2),...)
又有定理:
P(p^t)<=2(p+1)p^t (p>5)
更有定理:
P(m)<=6m
于是可以暴力
还有个显然的结论:
P(p^t)=P(p)*p^(t-1)
哈哈~讲课讲到这了
设P(m)为斐波那契模m的循环节
若m=p1^t1*p2^t2...
则P(m)=lcm(P(p1^t1),P(p2^t2),...)
又有定理:
P(p^t)<=2(p+1)p^t (p>5)
更有定理:
P(m)<=6m
于是可以暴力
还有个显然的结论:
P(p^t)=P(p)*p^(t-1)
哈哈~讲课讲到这了
//#define _TEST _TEST #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <cmath> #include <algorithm> using namespace std; /************************************************ Code By willinglive Blog:http://willinglive.cf ************************************************/ #define rep(i,l,r) for(int i=(l),___t=(r);i<=___t;i++) #define per(i,r,l) for(int i=(r),___t=(l);i>=___t;i--) #define MS(arr,x) memset(arr,x,sizeof(arr)) #define LL long long #define INE(i,u,e) for(int i=head[u];~i;i=e[i].next) inline const int read() {int r=0,k=1;char c=getchar();for(;c<'0'||c>'9';c=getchar())if(c=='-')k=-1; for(;c>='0'&&c<='9';c=getchar())r=r*10+c-'0';return k*r;} ///////////////////////////////////////////////// int m; LL ans; ///////////////////////////////////////////////// LL gcd(LL a,LL b){return b?gcd(b,a%b):a;} LL lcm(LL a,LL b){return a/gcd(a,b)*b;} int P(int m) { int x=1,y=1,z,t=1; while(1) { t++; z=(x+y)%m; x=y; y=z; if(x==0&&y==1) return t; } return 0; } ///////////////////////////////////////////////// void input() { m=read(); } void solve() { ans=1; for(int i=2;i*i<=m;i==2?i++:i+=2) if(m%i==0) { LL t=P(i); m/=i; while(m%i==0) m/=i,t*=i; ans=lcm(ans,t); } if(m>1) ans=lcm(ans,P(m)); cout<<ans<<endl; } ///////////////////////////////////////////////// int main() { #ifndef _TEST freopen("std.in","r",stdin); freopen("std.out","w",stdout); #endif rep(i,1,read()) input(),solve(); return 0; }
相关文章推荐
- [斐波那契循环节 数学技巧] HDU 3977 Evil teacher
- [原创]windows server 2012 AD架构试验系列 – 12 配置操作主机
- UVA11582Colossal Fibonacci Numbers!(斐波那契找循环节)
- BaiduStar 1.du熊学斐波那契I 找循环节
- <2012 12 16> gcc-ARM交叉编译器死活不支持math.h中的isnormal、isfinite两个宏
- <2012 12 24> 小技巧:关键计算代码建立内存索引表来增加算法速度
- <2012 12 25> 嵌入式工程师眼中的PLC
- (12)Visual Studio 2012如何透过电子邮件部署Xamarin.Android App
- Uva11582 Colossal Fibonacci Numbers! (数论、斐波那契循环节)
- 【2012-12】【组合计数】棋盘游戏
- GhostXP SP3 电脑城元旦装机版 2012 12
- Windows Server 2012 Hyper-V新特性(12)
- 针式PKM V9.70 最新版(2012_12_18)
- <2012 12 01> 三星Exynos3110 Cortex-A8 1GHz 处理器 蜂鸟 S5PC110 S5PV210
- Cheatsheet: 2012 03.01 ~ 03.12
- <2012 12 03> 使用JTAG接口进行裸板开发
- ORACLE游标实例讲解 (2012-12-1510:16:54)转载▼
- <2012 12 06>[转] U-boot研究与移植心得
- SCOM 2012知识分享-12:管理WEB控制台
- UVa11582 巨大的斐波那契数 循环节计算+快速幂