Cod sursa(job #1583659)

Utilizator Andreicm12Matraguna Andrei Andreicm12 Data 29 ianuarie 2016 10:26:19
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int powe (int a)
{
    long long b=a;
    int sol=1;
    while(b)
    {
        if(b%2==1){
            sol=sol*a%10;
        }
        a=a*a%10;
        b/=2;
    }
    return sol;
}
int cifra(int x)
{
    if(x==1)
        return 1;
    else
        return cifra(x-1)+powe(x)%10;
}
int main()
{
    int x, T;
    f>>T;
    for(int i=0; i<T; i++)
    {
        f>>x;
        g<<cifra(x)%10<<endl;
    }
    return 0;
}