Cod sursa(job #2699500)

Utilizator Dragono63Stanciu Rares Stefan Dragono63 Data 24 ianuarie 2021 18:21:22
Problema Cifra Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.63 kb
#include <bits/stdc++.h>

using namespace std;

/****************************************/
/// INPUT / OUTPUT

ifstream f("cifra.in");
ofstream g("cifra.out");
/****************************************/
/// GLOBAL DECALRATIONS

int T;
/****************************************/
/// FUNCTIONS

void ReadInput();
void Solution();
void Output();
/****************************************/
///-------------------------------------------------------
inline void ReadInput()
{
    f >> T;
}
///-------------------------------------------------------
long long CalculateProduct(int val)
{
    long long prod = 1;
    for(int i = 1 ; i <= val ; ++ i)
    {
        prod *= 1LL * val;
        prod %= 10;
    }
    return prod;
}
///-------------------------------------------------------
long long Solve(int num)
{
    long long sum = 0;
    for(int i = 1 ; i <= num ; ++ i)
    {
        sum += CalculateProduct(i);
        sum %= 10;
    }
    return sum;
}
///-------------------------------------------------------
inline void Solution()
{
    while(T--)
    {
        string N;
        f >> N;
        if(N.length() == 1)
        {
            int num = N[0] - '0';
            g << Solve(num) << "\n";
        }
        else
        {
            int num = (N[N.length() - 2] - '0') * 10 + (N[N.length() - 1] - '0');
            g << Solve(num) << "\n";
        }
    }
}
///-------------------------------------------------------
inline void Output()
{

}
///-------------------------------------------------------
int main()
{
    ReadInput();
    Solution();
    Output();
    return 0;
}