http://lightoj.com/volume_showproblem.php?problem=1282
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #include <assert.h> #define IOS ios::sync_with_stdio(false) using namespace std; #define inf (0x3f3f3f3f) typedef long long int LL; #include <iostream> #include <sstream> #include <vector> #include <set> #include <map> #include <queue> #include <string> #include <bitset> //int calc(LL a, LL b, int k) { //a^b的前k + 1位 // double res = b * log10(a * 1.0) - (LL)(b * log10(a * 1.0)); //小数部分 // return (int)pow(10.0, k + res); //} int calc(double a, LL b, int k) { double ans = 1, base = a; while (b) { if (b & 1) { ans = ans * base; } b >>= 1; base = base * base; while (ans >= 1000) ans /= 10; //保留前3位 while (base >= 1000) base /= 10; } return (int)ans; } int quick_pow(LL a, LL b, int MOD) { LL ans = 1, base = a % MOD; while (b) { if (b & 1) ans = ans * base % MOD; b >>= 1; base = base * base % MOD; } return ans; } void work() { LL a, b; cin >> a >> b; static int f = 0; printf("Case %d: %d %03d ", ++f, calc(a, b, 3), quick_pow(a, b, 1000)); } int main() { #ifdef local freopen("data.txt", "r", stdin); // freopen("data.txt", "w", stdout); #endif int t; scanf("%d", &t); while (t--) work(); return 0; }