Cod sursa(job #2392901)

Utilizator AnimusFabian Animus Data 30 martie 2019 16:17:52
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.75 kb
#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;
    }
}