Pagini recente » Profil kuweit | Rating Bulancea Melutu-Iulian (bulancea_melutu) | Cod sursa (job #1073895) | Cod sursa (job #2590295) | Cod sursa (job #2319643)
#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;
}