Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <fstream>
- #include <cmath>
- #include <set>
- #include <iomanip>
- #include <queue>
- #include <map>
- #define li long long
- #define forn(i, n) for (int i = 0; i < (int) n; ++i)
- #define all(a) a.begin(), a.end()
- using namespace std;
- inline void boost() {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- }
- bool fl = false;
- li modexp(li x, li y, li N)
- {
- if (y == 0) return 1;
- li z = modexp(x, y / 2, N);
- if (z * z >= N || z * z * x >= N)
- fl = true;
- if (y % 2 == 0)
- return (z * z) % N;
- else
- return (((x * z) % N) * z) % N;
- }
- const li MOD = 1e9;
- const li MOD2 = 1e5;
- int main() {
- boost();
- int t;
- cin >> t;
- while (t--)
- {
- li n, k;
- cin >> k >> n;
- li F = modexp(k, n, MOD2);
- string ans = to_string(F);
- if (fl)
- while (ans.length() < 5)
- ans = '0' + ans;
- cout << ans << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement