#include <iostream>
using namespace std;
#define int long long
int power(int a, int b, int p)
{int ans = 1;while (b){if (b % 2){ans *= a;ans %= p; // 随时取模}a *= a;a %= p; // 随时取模b /= 2;}return ans;
}
signed main()
{int a, b, p;cin >> a >> b >> p;int res = power(a, b, p);res %= p;cout << a << "^" << b << " mod " << p << "=" << res;return 0;
}
Shortest path of the king
#include <iostream>
#include <string>
using namespace std;
int res;
string s[1000];
string a, b;
int x, y;
int main()
{cin >> a >> b;x = (a[0] - 'a') - (b[0] - 'a');y = (a[1] - '0') - (b[1] - '0');while (x > 0 && y > 0){s[res] = "LD";res++;x--;y--;}while (x < 0 && y < 0){s[res] = "RU";res++;x++;y++;}while (x > 0 && y < 0){s[res] = "LU";res++;x--;y++;}while (x < 0 && y > 0){s[res] = "RD";res++;x++;y--;}while (x > 0){s[res] = "L";res++;x--;}while (x < 0){s[res] = "R";res++;x++;}while (y > 0){s[res] = "D";res++;y--;}while (y < 0){s[res] = "U";res++;y++;}cout << res << endl;for (int i = 0; i < res; i++){cout << s[i] << endl;}return 0;
}