Cod sursa(job #2879917)

Utilizator AndreiDragosDavidDragos Andrei David AndreiDragosDavid Data 29 martie 2022 10:45:47
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
//on the first line of the file cifra.in, there will be a number t
//followed by t numbers separated by new lines
//find the last digit of the sum 1^1+ 2^2 + ... + t^t for each t
//and print it in the file cifra.out

#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

int main()
{
    ifstream fin("cifra.in");
    ofstream fout("cifra.out");
    int t;
    fin >> t;
    for (int i = 0; i < t; i++)
    {
        int n;
        fin >> n;
        int sum = 0;
        for (int j = 1; j <= n; j++)
        {
            sum += pow(j, j);
        }
        fout << sum % 10 << endl;
    }
    fin.close();
    fout.close();
    return 0;
}