Pagini recente » Cod sursa (job #2202798) | Cod sursa (job #3167239) | Cod sursa (job #1073479) | Cod sursa (job #2109502) | Cod sursa (job #2319749)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int i,j,n,m;
#define ll long long
long long suma;
long long rez2(ll x){
ll y, h;
ll rez;
y = x;
x %= 10;
if(x == 0) return 0;
if(x == 1) return 1;
if(x == 2){
h = y % 4;
if(h == 1) return 2;
if(h == 2) return 4;
if(h == 3) return 8;
if(h == 0) return 6;
}
if(x == 3){
h = y % 4;
if(h == 1) return 3;
if(h == 2) return 9;
if(h == 3) return 7;
if(h == 0) return 1;
}
if(x == 4){
h = y % 2;
if(h == 1) return 4;
if(h == 0) return 6;
}
if(x == 5) return 5;
if(x == 6) return 6;
if(x == 7){
h = y % 4;
if(h == 1) return 7;
if(h == 2) return 9;
if(h == 3) return 3;
if(h == 4) return 1;
}
if(x == 8){
h = y % 4;
if(h == 1) return 8;
if(h == 2) return 4;
if(h == 3) return 2;
if(h == 0) return 6;
}
if(x == 9){
h = y % 2;
if(h == 1) return 9;
if(h == 2) return 1;
}
// return rez;
}
int main()
{
j = 0;
f >> m;
while(j < m){
f >> n;
j++;
suma = 0;
for(int i = 1; i <= n; ++i)
suma+=rez2(i) % 10;
g << suma % 10 << "\n";
}
//getch();
f.close();
g.close();
return 0;
}