Cod sursa(job #1133298)

Utilizator blackchangeMarius Blaj blackchange Data 4 martie 2014 18:31:47
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ifstream fcin("cifra.in");
    ofstream fcout("cifra.out");
    int t,n,j,x,i,j1,s;
    fcin>>t;
    for (i=1;i<=t;i++)
    {
        fcin>>n;s=0;
        for (j=1;j<=n;j++)
        {
            x=j%10;j1=j;
            while (j1>1)
            {
                x=x*(j%10);
                if (x>9)
                    x=x%10;
                j1--;
            }
            s=s+x;
            if (s>9)
                s=s%10;
        }
        fcout<<s<<endl;
    }


    fcin.close();
    fcout.close();
    return 0;
}