Cod sursa(job #1671075)

Utilizator dragos000Cojanu Dragos dragos000 Data 1 aprilie 2016 12:00:18
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <iostream>
#include <cstring>
#include <fstream>
#include <cstdlib>

using namespace std;

int putere(long unsigned n, int p)
{
    long unsigned x=1;
    while (p)
    {
        if (p&1)
        {
            x=(x*n)%100;
            p--;
        }
        else
        {
            n=(n*n)%100;
            p/=2;
        }
    }
    return x%10;
}
int v[100];

int main()
{
    char n[100];

    for(int i=1; i<100; i++)
    {
        v[i]+=(v[i-1]+putere(i,i))%10;
    }


    ofstream g("cifra.out");
    ifstream f("cifra.in");
    while(f.getline(n,100))
    {
        if(strlen(n)>2)strcpy(n,n+strlen(n)-2);
        g<<v[atoi(n)]<<"\n";
    }

    g.close();
    f.close();


}