Cod sursa(job #2319643)

Utilizator valkir69Radu Andrei valkir69 Data 13 ianuarie 2019 21:57:05
Problema Cifra Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.43 kb
#include    <iostream>
#include    <fstream>

using namespace std;

ifstream f("cifra.in");
ofstream g("cifra.out");

int i,j,n,m;

#define ll long long

ll suma;

ll rez2(ll x){
    ll y, h;
    ll rez;
    y = x;
    x %= 10;
    if(x == 0) rez = 0;
    if(x == 1) rez = 1;
    if(x == 2){
        h = y % 4;
        if(h == 1) rez = 2;
        if(h == 2) rez = 4;
        if(h == 3) rez = 8;
        if(h == 0) rez = 6;
    }
    if(x == 3){
        h = y % 4;
        if(h == 1) rez = 3;
        if(h == 2) rez = 9;
        if(h == 3) rez = 7;
        if(h == 0) rez = 1;

    }
    if(x == 4){
        h = y % 2;
        if(h == 1) rez = 4;
        if(h == 0) rez = 6;
    }
    if(x == 5) rez = 5;
    if(x == 6) rez = 6;
    if(x == 7){
        h = y % 4;
        if(h == 1) rez = 7;
        if(h == 2) rez = 9;
        if(h == 3) rez = 3;
        if(h == 4) rez = 1;
    }
    if(x == 8){
        h = y % 4;
        if(h == 1) rez = 8;
        if(h == 2) rez = 4;
        if(h == 3) rez = 2;
        if(h == 0) rez = 6;
    }
    if(x == 9){
        h = y % 2;
        if(h == 1) rez = 9;
        if(h == 2) rez = 1;
    }
    return rez;
}

int main()
{
    j = 0;
    while(j < m){
        f >> n;
        j++;
        suma = 0;
        for(int i = 1; i <= n; ++i)
            suma+=rez2(i) % 10;
        g << suma % 10;
    }
    f.close();
    g.close();
    return 0;
}