Cod sursa(job #2455372)

Utilizator AlexNeaguAlexandru AlexNeagu Data 11 septembrie 2019 17:11:05
Problema Cifra Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("cifra.in");
ofstream out("cifra.out");
int v[105];
int convertThisShit(string s) {
  int ans = 0;
  ans = ans * 10 + (s[0] - '0');
  ans = ans * 10 + (s[1] - '0');
  return ans;
}
int pow(int base, int x) {
  int r = 1;
  while(x) {
    if (x & 1) r = (r * base) % 10;
    base = (base * base) % 10;
    x /= 2;
  }
  return r;
}
int main() {
  for (int i = 1; i <= 100; i++) {
    v[i] = (v[i - 1] + pow(i, i)) % 10;
  }
  int t; in >> t;
  while(t--) {
    string n, num; in >> n;
    n = "00" + n; int l = n.size() - 1;
    num = num + n[l - 1] + n[l];
    int x = convertThisShit(num);
    // cout << x << "\n";
    out << v[x] << "\n";
  }
}