Cod sursa(job #3327702)

Utilizator Cristian.p08Popescu Cristian Cristian.p08 Data 4 decembrie 2025 20:06:54
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 3.77 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("cifra.in");
ofstream fout("cifra.out");
int putere(int n, unsigned int p)
{
    int rezultat=1;
    while(p>0)
    {
        if(p%2==1)
        {
            rezultat=rezultat*n;
        }
        n=n*n;
        p=p/2;
    }
    return rezultat;
}
int main()
{
    int T,x,S=0,i,cif,cif2;
    fin>>T;
    while(T!=0)
    {
        S=0;
        i=0;
        fin>>x;

       while(i<x)
       {
        i++;
       cif=i%10;
       if(cif==0)
       {

       }
       else
       {
           if(cif==1)
           {
               S=S+1;
           }
           else
           {
               if(cif==2)
               {
                   cif2=i%4;
                    if(cif2==0)
                       {
                           cif2=4;
                       }
                  S=S+putere(cif,cif2)%10;
               }
               else
               {
                   if(cif==3)
                   {
                       cif2=i%4;
                       if(cif2==0)
                       {
                           cif2=4;
                       }
                  S=S+putere(cif,cif2)%10;
                   }
                   else
                   {
                       if(cif==4)
                       {
                            cif2=i%2;
                             if(cif2==0)
                       {
                           cif2=4;
                       }
                  S=S+putere(cif,cif2)%10;
                       }
                       else
                       {
                           if(cif==5)
                           {
                               S=S+5;
                           }
                           else
                           {
                               if(cif==6)
                               {
                                   S=S+6;
                               }
                               else
                               {
                                   if(cif==7)
                                   {
                                      cif2=i%4;
                                       if(cif2==0)
                       {
                           cif2=4;
                       }
                                    S=S+putere(cif,cif2)%10;
                                   }
                                   else
                                   {
                                       if(cif==8)
                                       {
                                            cif2=i%4;
                                             if(cif2==0)
                       {
                           cif2=4;
                       }
                                    S=S+putere(cif,cif2)%10;
                                       }
                                       else
                                       {
                                           if(cif==9)
                                           {
                                               cif2=i%2;
                                                if(cif2==0)
                                                   {
                                                    cif2=2;
                                                   }

                                                S=S+putere(cif,cif2)%10;
                                           }
                                       }
                                   }
                               }
                           }
                       }
                   }
               }
           }
       }
       }
       fout<<S%10<<endl;
       T--;
    }
    return 0;
}