https://www.acmicpc.net/problem/1009
#include <iostream>
#include <map>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
// freopen("input.txt", "r", stdin);
int t;
cin >> t; // 테스트 케이스 개수 입력 받기
for (int i = 0; i < t; i++)
{
int a, b, result = 1; // 결과값을 1로 초기화 시켜줘야 값을 매번 저장해가며 계산 가능
cin >> a >> b;
for (int j = 0; j < b; j++)
{
// 마지막 자릿수만 필요
result = (result * a) % 10; // 거듭제곱한 결과값 저장
}
if (result == 0)
{
cout << 10 << endl; // 10의 거듭제곱의 경우
}
else
{
cout << result << endl;
}
}
return 0;
}
'백준' 카테고리의 다른 글
[C++] 백준 고층 건물 (0) | 2024.06.18 |
---|---|
[C++] 백준 투명 (0) | 2024.06.18 |
[C++] 백준 나누기 (0) | 2024.06.16 |
[C++] 백준 DNA 해독 (1) | 2024.01.30 |
[C++] 백준 평균은 넘겠지 (0) | 2024.01.23 |