Advertisement
Infiniti_Inter

Untitled

Feb 15th, 2020
280
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. bool fl = false;
  31. li modexp(li x, li y, li N)
  32. {
  33. if (y == 0) return 1;
  34. li z = modexp(x, y / 2, N);
  35. if (z * z >= N || z * z * x >= N)
  36. fl = true;
  37. if (y % 2 == 0)
  38. return (z * z) % N;
  39. else
  40. return (((x * z) % N) * z) % N;
  41. }
  42. const li MOD = 1e9;
  43. const li MOD2 = 1e5;
  44.  
  45. int main() {
  46. boost();
  47. int t;
  48. cin >> t;
  49. while (t--)
  50. {
  51. li n, k;
  52. cin >> k >> n;
  53. li F = modexp(k, n, MOD2);
  54. string ans = to_string(F);
  55. if (fl)
  56. while (ans.length() < 5)
  57. ans = '0' + ans;
  58. cout << ans << endl;
  59.  
  60.  
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement