Rightmost Digit
Given a positive integer N, you should output the most right digit of N^N…
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Output
For each test case, you should output the rightmost digit of N^N.
题目大意:
找到N的N次方的个位数
个位数会以4为周期进行循环

找到规律之后就很好做了。
附代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T, x, a[4];
cin >> T;
while (T--)
{
cin >> x;
int t = x % 10;
int num = t;
for (int i = 0; i < 4; i++)
a[i] = (num *= t) % 10;
cout << a[(x - 2) % 4] << endl;
}
}
399

被折叠的 条评论
为什么被折叠?



