Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- long long int A[2][2] = {{1,1},{1,0}};#this is a matrix
- n = n-1;
- long long int B[2][2] = {{1,0},{0,1}};#this is a matrix
- while(n>0)#repeat the following procedure until n becomes 0
- {
- if(n%2==1)#when is odd
- mult(B,A);
- n = n/2;
- mult(A,A);
- }
- long long int result = ((power(pp+1,B[0][1])*power(p+1,B[0][0]))%mod - 1 + mod)%mod;
- printf("%lldn",result);
- void mult(long long int A[2][2],long long int B[2][2])
- {
- long long int C[2][2];
- C[0][0] = A[0][0]*B[0][0] + A[0][1]*B[1][0];
- C[0][1] = A[0][0]*B[0][1] + A[0][1]*B[1][1];
- C[1][0] = A[1][0]*B[0][0] + A[1][1]*B[1][0];
- C[1][1] = A[1][0]*B[0][1] + A[1][1]*B[1][1];
- A[0][0] = C[0][0]%(mod-1);
- A[0][1] = C[0][1]%(mod-1); #mod is some no since answer is asked in mod
- A[1][0] = C[1][0]%(mod-1);
- A[1][1] = C[1][1]%(mod-1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement