Pagini recente » Cod sursa (job #1511161) | Cod sursa (job #2974179) | Cod sursa (job #1590981) | Cod sursa (job #1743279) | Cod sursa (job #2392901)
#include <iostream>
#include <string>
using namespace std;
int lstciftop(int c, int p){
if(c == 0) return 0;
if(c == 1) return 1;
int c1 = c;
int c2 = (c * c)%10;
int c3 = (c * c * c)%10;
int c4 = (c * c * c * c)%10;
if(p % 4 == 0) return c4;
if(p % 4 == 1) return c1;
if(p % 4 == 2) return c2;
if(p % 4 == 3) return c3;
}
int main()
{
//ios::sync_with_stdio(false);
freopen("cifra.in", "r", stdin);
freopen("cifra.out", "w", stdout);
int t; cin >> t;
for(; t > 0; t--){
string nr; cin >> nr;
int sum = 0;
for(int i = 1; i <= nr[nr.length()-1] -'0'; i++){
sum += lstciftop(i, i);
}
cout << sum%10 << endl;
}
}