#include using namespace std; typedef long long LL; int main() { LL base = 34; // 数字n int digits = 2; // 后2位 LL mod = 100; int k = 20; // 执行多少次方模拟 LL result = 1; // Initialize result (base^0 = 1) map st; // Track positions of trailing digits int cycle_start = -1, cycle_length = -1; for (int i = 1; i <= k; i++) { result = (result * base) % mod; // Calculate trailing digits of base^i printf("%d^%2d = %40lld trailing digits: %02lld", base, i, (LL)pow(base, i), result); if (st[result]) { cycle_start = st[result]; cycle_length = i - cycle_start; printf(" \n\nCycle detected! Starts at %d, length = %d\n", cycle_start, cycle_length); break; } st[result] = i; printf("\n"); } if (cycle_length != -1) { cout << "\n============================\n"; cout << "Simulation result: Trailing 2 digits cycle length = " << cycle_length << endl; } return 0; }