Cod sursa(job #1779046)

Utilizator Andrei1998Andrei Constantinescu Andrei1998 Data 14 octombrie 2016 18:27:02
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <fstream>
#include <algorithm>
#include <string>

using namespace std;

int raise(int a, int b) {
    int ans = 1;
    for (int i = 0; i < b; ++ i)
        ans = (ans * a) % 10;
    return ans;
}

int all[105];

int main()
{
    ifstream cin("cifra.in");
    ofstream cout("cifra.out");

    for (int i = 1; i <= 105; ++ i)
        all[i] = (all[i - 1] + raise(i % 10, i)) % 10;

    int t = 0;
    cin >> t;

    string str;
    while (t --) {
        cin >> str;
        reverse(str.begin(), str.end());

        while (str.size() < 2)
            str += '0';

        int nr = (str[1] - '0') * 10  +
                 (str[0] - '0');

        cout << all[nr] << '\n';
    }

    cin.close();
    cout.close();
    return 0;
}