๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 1009๋ฒˆ - ๋ถ„์‚ฐ์ฒ˜๋ฆฌ

by dkswnkk 2021. 10. 16.
 

1009๋ฒˆ: ๋ถ„์‚ฐ์ฒ˜๋ฆฌ

์ž…๋ ฅ์˜ ์ฒซ ์ค„์—๋Š” ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์˜ ๊ฐœ์ˆ˜ T๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. ๊ทธ ๋‹ค์Œ ์ค„๋ถ€ํ„ฐ ๊ฐ๊ฐ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค์— ๋Œ€ํ•ด ์ •์ˆ˜ a์™€ b๊ฐ€ ์ฃผ์–ด์ง„๋‹ค. (1 ≤ a < 100, 1 ≤ b < 1,000,000)

www.acmicpc.net

 

//  Copyright © 2021 ์•ˆ์ฃผํ˜•. All rights reserved.
//
//  https://www.acmicpc.net/problem/1009
//  BOJ1009 ๋ถ„์‚ฐ์ฒ˜๋ฆฌ
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int N; cin >> N;
    while (N--) {
        int a, b; cin >> a >> b;
        if (b % 4 == 0)b = 4;    //๋ชจ๋“  ์ œ๊ณฑ๋“ค์ด 4์˜ ์ฃผ๊ธฐ๋ฅผ ๊ฐ€์ง.
        else b %= 4;
        long long final = pow(a, b);
        if (final % 10 == 0) cout << 10<<"\n";
        else  cout << final % 10 << "\n";
    }
}

๋Œ“๊ธ€