Cod sursa(job #324155)

Utilizator dacyanMujdar Dacian dacyan Data 14 iunie 2009 18:44:35
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <fstream>
#include <cmath>
#include <iostream>
using namespace std;

ifstream fin("cifra.in");
ofstream fout("cifra.out");

int main()
{
    long a[101] = {0};
    long i, j, t, rez, x;
    
    for ( i = 1; i < 101; i++)
    {
       rez = 1;
       for(j = 1; j <= i;j++)
       {
              rez *= i;
              rez = rez % 10;
       }    
       a[i] = (rez  + a[i-1]) %10;
    }
    fin >> t;
    for ( i = 0 ; i < t; i++)
    {
        fin >> x;
        if ( x > 100)
                x = x % 100;
        fout << a[x]  << '\n';
    }    
    fin.close();
    fout.close();
    
    return 0;
}