Pagini recente » Cod sursa (job #1150422) | Cod sursa (job #1453230) | Rating EEEE (Epurasu_) | Cod sursa (job #2827757) | Cod sursa (job #2265916)
#include <iostream>
#include <fstream>
using namespace std;
long a, n, S, T, i;
int ultcif(int a, int n) {
if (a % 10 == 4)
if (n % 2 == 0)
return 6;
else
return 4;
else if (a % 10 == 1)
return 1;
else if (a % 10 == 2) {
if (n % 4 == 0)
return 6;
else if (n % 4 == 1)
return 2;
else if (n % 4 == 2)
return 4;
else if (n % 4 == 3)
return 8;
}
else if (a % 10 == 3) {
if (n % 4 == 0)
return 1;
else if (n % 4 == 1)
return 3;
else if (n % 4 == 2)
return 9;
else if (n % 4 == 3)
return 7;
}
else if (a % 10 == 5)
return 5;
else if (a % 10 == 6)
return 6;
else if (a % 10 == 7) {
if (n % 4 == 0)
return 1;
else if (n % 4 == 1)
return 7;
else if (n % 4 == 2)
return 9;
else if (n % 4 == 3)
return 3;
}
else if (a % 10 == 8) {
if (n % 4 == 0)
return 6;
else if (n % 4 == 1)
return 8;
else if (n % 4 == 2)
return 4;
else if (n % 4 == 3)
return 2;
}
else if (a % 10 == 9) {
if (n % 2 == 0)
return 1;
else
return 9;
}
}
int main() {
ifstream fin("cifra.in.txt");
ofstream fout("cifra.out.txt");
fin >> T;
for (i = 1; i <= T + 1; i++) {
S = 0;
fin >> n;
for (i = 1; i <= n; i++)
S = S + ultcif(i, i);
fout << S % 10 << endl;
}
return 0;
}