Cod sursa(job #2884474)
| Utilizator | Data | 3 aprilie 2022 19:06:42 | |
|---|---|---|---|
| Problema | Cifra | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.67 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream f("modulo.in");
ofstream g("modulo.out");
#define cin f
#define cout g
int power(int n) {
int p = n;
int ans = 1;
while(p) {
if(p % 2 == 1) {
ans = (ans * n) % 10;
p--;
}
n = (1LL * n * n) % 10;
p /= 2;
}
return ans;
}
int main() {
const int N = 1e5;
int arr[N + 1];
arr[1] = 1;
for(int i = 2; i <= N; i++) {
arr[i] = (arr[i - 1] + power(i)) % 10;
}
int t;
cin >> t;
while(t--) {
int a;
cin >> a;
cout << arr[a] << "\n";
}
return 0;
}