Cod sursa(job #1671071)

Utilizator dragos000Cojanu Dragos dragos000 Data 1 aprilie 2016 11:53:35
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 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];
	ifstream f("cifra.in");
	f.getline(n,100);
	f.close();

    if(strlen(n)>2)strcpy(n,n+strlen(n)-2);


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

    ofstream g("cifra.out");
    g<<v[atoi(n)];
    g.close();


}