BJFU 1057
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了BJFU 1057相关的知识,希望对你有一定的参考价值。
描述
斐波那契额数列,我们都知道。现在qingyezhu想求斐波那契的某项值对2的某次方的结果。你可以帮一下他吗?他好可怜哦!计算了N的N次方次都错了,也挨了ben大哥的N的N次方次的训了。我想你是个好孩子,该会帮他一下吧。不会浪费你多久的时间的。如下是斐波那契数列的定义:
F[0]=1,F[1]=1,F[i]=F[i-1]+F[i-2],其中i>=2.
输入
输入有多组。每一组两个非负数M(0<=M<32)和N(0<=N<92),之间用空格隔开,且每一组数据占一行。
输出
对每组输入数据,请输出F[N]对2^M的求余的结果,每组结果占一行!
样例输入
2 2
2 3
5 28
样例输出
2
3
21
也是被网上不良小工具给坑了,斐波那契的表最后十几个值全都不对,一直WA了二十几次,后来自己写了个斐波那契的函数打出来的数才AC了↓
1 #include <iostream> 2 using namespace std; 3 int main() 4 { 5 long long n,m; 6 while(cin>>m>>n) 7 { 8 long long fib[] = {1,1,2,3,5,8,13,21,34,55,89,144,233, 9 377,610,987,1597,2584,4181,6765,10946 ,17711, 28657, 10 46368, 75025, 121393, 196418, 317811 ,514229 ,832040 ,1346269 , 11 2178309LL ,3524578LL ,5702887LL ,9227465LL ,14930352LL ,24157817LL , 12 39088169LL ,63245986LL ,102334155LL ,165580141LL ,267914296LL ,433494437LL, 13 701408733LL ,1134903170LL ,1836311903LL ,2971215073LL ,4807526976LL, 14 7778742049LL ,12586269025LL ,20365011074LL ,32951280099LL ,53316291173LL, 15 86267571272LL ,139583862445LL ,225851433717LL ,365435296162LL , 16 591286729879LL ,956722026041LL ,1548008755920LL ,2504730781961LL, 17 4052739537881LL ,6557470319842LL ,10610209857723LL ,17167680177565LL, 18 27777890035288LL ,44945570212853LL ,72723460248141LL ,117669030460994LL, 19 190392490709135LL ,308061521170129LL ,498454011879264LL, 20 806515533049393LL ,1304969544928657LL ,2111485077978050LL, 21 3416454622906707LL ,5527939700884757LL ,8944394323791464LL , 22 14472334024676221LL ,23416728348467685LL ,37889062373143906LL , 23 61305790721611591LL ,99194853094755497LL ,160500643816367088LL , 24 259695496911122585LL ,420196140727489673LL ,679891637638612258LL , 25 1100087778366101931LL ,1779979416004714189LL ,2880067194370816120LL , 26 4660046610375530309LL,7540113804746346429LL 27 }; 28 long long twow[]= 29 { 30 1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768LL,65536LL, 31 131072LL,262144LL,524288LL,1048576LL,2097152LL,4194304LL,8388608LL,16777216LL,33554432LL, 32 67108864LL,134217728LL,268435456LL,536870912LL,1073741824LL,2147483648LL 33 }; 34 cout<<(fib[n]&(twow[m]-1))<<endl; 35 } 36 return 0; 37 }
以上是关于BJFU 1057的主要内容,如果未能解决你的问题,请参考以下文章