Pagini recente » Cod sursa (job #2446932) | Cod sursa (job #3151595) | Cod sursa (job #787077) | Cod sursa (job #2936119) | Cod sursa (job #2879917)
//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;
}