Pagini recente » Cod sursa (job #324543) | Cod sursa (job #2884197)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("cifra.in");
ofstream fout("cifra.out");
int pow2(int a, int b){
int ultima = 1;
while(b){
if(b % 2 == 1) ultima = (ultima * a) % 10;
a = (a*a) % 10;
b /= 2;
}
return ultima % 10;
}
string s; int64_t t, cnt;
int main(){
fin >> t;
for(int i = 1; i <= t; i++){
fin >> s;
int k = s[s.length() - 1] - '0'; cnt = 0;
if(k == 1) fout << 1 << '\n';
else{
for(int j = 2; j <= k; j++){
cnt += pow2(j, j);
}
fout << (cnt + 1) % 10 << '\n';
}
}
}