CFR 742 A. Arpa’s hard exam and Mehrdad’s naive cheat ( Ad hoc, Periodic )
題意:
求 1378 ^ N 的最後一位數字
資料規模:
0 ≤ N ≤ 1e9
解法:
當 N = 0,是 1。
否則會循環,如 8, 4, 2, 6, 8, 4, 2, 6, ...
時間 / 空間複雜度:
O( 1 )
int N; void init(){ cin >> N; } void solve(){ // 1, 8, 4, 2, 6, 8, 4, 2, 6.. if( N == 0 ) cout << 1 << endl; else{ --N; N %= 4; if( N == 0 ) cout << 8 << endl; else if( N == 1 ) cout << 4 << endl; else if( N == 2 ) cout << 2 << endl; else cout << 6 << endl; } }