Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* nth fibonacci number */
- void fib(ll n, ll&x, ll&y){
- if(n==0){
- x = 0;
- y = 1;
- return ;
- }
- if(n&1){
- fib(n-1, y, x);
- y=(y+x)%mod;
- }else{
- ll a, b;
- fib(n>>1, a, b);
- y = (a*a+b*b)%mod;
- x = (a*b + a*(b-a+mod))%mod;
- }
- }
- //answer in x. no map, time — logN.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement