Cod sursa(job #2791845)

Utilizator WtfIsThisNeagu Andrei WtfIsThis Data 31 octombrie 2021 11:15:45
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.64 kb
#include <fstream>
	
using namespace std;

ifstream fin("cifra.in");
ofstream fout("cifra.out");

long long rez(long long a, long long b){
    int rez=1;
    while(b){
        if(b&1)
            rez=(rez*a)%10;
        a=(a*a)%10;
        b=b/2;
    }
    return rez;
}

long long putere[105], n;
int T, size;
int main()
{
    for(long long i=1; i<=100; i++)
        putere[i]=(putere[i-1]+rez(i,i))%10;
    fin >> T;
    while (T--)
    {
        string str;
        fin >> str;
        n=0, size = str.length();
        for(long long k=max(0, size-2); k<=size-1; k++)
            n=n*10+str[k]-'0';
        fout << putere[n] << "\n";
    }
    return 0;  
}