Cod sursa(job #3351089)

Utilizator IvanAndreiIvan Andrei IvanAndrei Data 16 aprilie 2026 18:07:49
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <bits/stdc++.h>  

using namespace std; 

int ans[21];

void solve()
{
    int t;
    cin >> t;
    for (int i = 1; i <= 20; i++)
    {
        int x = 1;
        for (int j = 1; j <= i; j++)
        {
            x = (x * i) % 10;
        }
        ans[i] = (ans[i - 1] + x) % 10;
    }
    while (t--)
    {
        string s;
        cin >> s;
        int n = 0;
        if (s.size() == 1)
        {
            n = s[0] - '0';
        }
        else
        {
            n = (s[s.size() - 2] - '0') * 10 + (s[s.size() - 1] - '0');
        }
        n %= 20;
        cout << ans[n] << "\n";
    }
}
  
signed main() 
{ 
#ifdef LOCAL 
    freopen("test.in", "r", stdin); 
    freopen("test.out", "w", stdout);
#else
    freopen("cifra.in", "r", stdin); 
    freopen("cifra.out", "w", stdout);
#endif // LOCAL 
    ios_base::sync_with_stdio(false); 
    cin.tie(0); 
    cout.tie(0); 
    long long tt; 
    tt = 1;
    while (tt--)
    {
        solve();
    }
    return 0; 
}