Advertisement
Infiniti_Inter

Untitled

Feb 15th, 2020
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include <iostream>
  4. #include <vector>
  5. #include <string>
  6. #include <algorithm>
  7. #include <fstream>
  8. #include <cmath>
  9. #include <set>
  10. #include <iomanip>
  11. #include <queue>
  12. #include <map>
  13.  
  14. #define li long long
  15. #define forn(i, n) for (int i = 0; i < (int) n; ++i)
  16. #define all(a) a.begin(), a.end()
  17.  
  18. using namespace std;
  19.  
  20. inline void boost() {
  21. #ifdef _DEBUG
  22. freopen("input.txt", "r", stdin);
  23. freopen("output.txt", "w", stdout);
  24. #endif
  25. ios_base::sync_with_stdio(false);
  26. cin.tie(0);
  27. cout.tie(0);
  28. }
  29.  
  30. li modexp(li x, li y, li N)
  31. {
  32. if (y == 0) return 1;
  33. li z = modexp(x, y / 2, N);
  34. if (y % 2 == 0)
  35. return (z * z) % N;
  36. else
  37. return (((x * z) % N) * z) % N;
  38. }
  39. const li MOD = 1e9;
  40. const li MOD2 = 1e9 + 13;
  41.  
  42. int main() {
  43. boost();
  44. int t;
  45. cin >> t;
  46. while (t--)
  47. {
  48. li n, k;
  49. cin >> k >> n;
  50. li F = modexp(k, n, MOD2);
  51. string ans = to_string(F);
  52. if (ans.length() >= 5)
  53. for (int i = ans.length() - 5; i < ans.length(); ++i)
  54. cout << ans[i];
  55. else
  56. cout << ans;
  57. cout << endl;
  58.  
  59.  
  60. }
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement