Advertisement
MegaVerkruzo

Untitled

Oct 11th, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int INF = 1e9;
  6.  
  7. long long pow(long long a, int n, long long m) {
  8. if (n == 0) {
  9. return 1;
  10. }
  11. if (n % 2 == 0) {
  12. long long half = pow(a, n / 2, m);
  13. return half * half % m;
  14. } else {
  15. return a * pow(a, n - 1, m) % m;
  16. }
  17. }
  18.  
  19. int main()
  20. {
  21. int t;
  22. cin >> t;
  23. for (; t > 0; --t) {
  24. long long a;
  25. long long m = 1e9 + 9;
  26. cin >> a;
  27. cout << pow(a, m - 1, m) - 1 << "\n";
  28. }
  29.  
  30. return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement