Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. long long int A[2][2] = {{1,1},{1,0}};#this is a matrix
  2. n = n-1;
  3. long long int B[2][2] = {{1,0},{0,1}};#this is a matrix
  4. while(n>0)#repeat the following procedure until n becomes 0
  5. {
  6. if(n%2==1)#when is odd
  7. mult(B,A);
  8. n = n/2;
  9. mult(A,A);
  10. }
  11. long long int result = ((power(pp+1,B[0][1])*power(p+1,B[0][0]))%mod - 1 + mod)%mod;
  12. printf("%lldn",result);
  13. void mult(long long int A[2][2],long long int B[2][2])
  14. {
  15. long long int C[2][2];
  16. C[0][0] = A[0][0]*B[0][0] + A[0][1]*B[1][0];
  17. C[0][1] = A[0][0]*B[0][1] + A[0][1]*B[1][1];
  18. C[1][0] = A[1][0]*B[0][0] + A[1][1]*B[1][0];
  19. C[1][1] = A[1][0]*B[0][1] + A[1][1]*B[1][1];
  20. A[0][0] = C[0][0]%(mod-1);
  21. A[0][1] = C[0][1]%(mod-1); #mod is some no since answer is asked in mod
  22. A[1][0] = C[1][0]%(mod-1);
  23. A[1][1] = C[1][1]%(mod-1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement