Advertisement
Infiniti_Inter

Untitled

Feb 15th, 2020
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 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. const double pi = acos(-1);
  31. const long long INF = 1e17 + 13;
  32. const li N = 1e5;
  33.  
  34. inline li mult(li a, li b) {
  35. return (a * b) % N;
  36. }
  37.  
  38. inline li binpow(li k, li n) {
  39. li ans = 1;
  40. while (n > 0) {
  41. if (n % 2 == 1) {
  42. ans = mult(ans, k);
  43. }
  44. n /= 2;
  45. k = mult(k, k);
  46. }
  47. return ans;
  48. }
  49.  
  50. int ans[220];
  51. int main() {
  52. boost();
  53.  
  54. int t;
  55. cin >> t;
  56. while (t--) {
  57. long long k, n;
  58. cin >> k >> n;
  59.  
  60. li ans = binpow(k, n);
  61. if (ans != 0) {
  62. cout << binpow(k, n) % N;
  63. }
  64. else {
  65. for (int i = 0; i < 5; i++) {
  66. cout << 0;
  67. }
  68. }
  69. if (t != 0) {
  70. cout << endl;
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement