Cod sursa(job #1489486)

Utilizator stanciuandreiStanciulescu Andrei stanciuandrei Data 21 septembrie 2015 11:08:10
Problema Cifra Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.44 kb
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
ifstream in("cifra.in");
ofstream out("cifra.out");
int lpow(int n)
{
    if(n%10==0 || n%10==1 || n%10==5 || n%10==6)
        return n%10;
    if(n%10==2)
    {
        switch(n%4)
        {
            case 1:return 2;
            case 2:return 4;
            case 3:return 8;
            case 4:return 6;
        }
    }
    if(n%10==3)
    {
        switch(n%4)
        {
            case 1:return 3;
            case 2:return 9;
            case 3:return 7;
            case 4:return 1;
        }
    }
    if(n%10==4)
    {
        if(n%2==1)
            return 4;
        else
            return 6;
    }
    if(n%10==7)
    {
        switch(n%4)
        {
            case 1:return 7;
            case 2:return 9;
            case 3:return 3;
            case 4:return 1;
        }
    }
    if(n%10==8)
    {
        switch(n%4)
        {
            case 1:return 8;
            case 2:return 4;
            case 3:return 2;
            case 4:return 6;
        }
    }
    if(n%10==9)
    {
        if(n%2==1)
            return 9;
        else
            return 1;
    }
    return -1;
}
int main()
{
    int c, l=0;
    int t;
    in>>t;
    for(; t>0; t--)
    {
        in>>c;
        l=0;
        for(int i=1;i<=c;++i)
            l=(l+lpow(i))%10;
        out<<l<<"\n";
    }
    return 0;
}