Cod sursa(job #2140220)

Utilizator AlexandruLuchianov1Alex Luchianov AlexandruLuchianov1 Data 23 februarie 2018 08:17:57
Problema Cifra Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

ifstream in ("cifra.in");
ofstream out ("cifra.out");

int lastcif(int n ,int k){
  if(k == 0)
    return 1;
  else{
    k %= 4;
    if(k == 0)
      k = 4;
    int result = 1;
    for(int i = 1 ; i <= k ;i++){
      result *= n;
      result %= 10;
    }
    return result;
  }
}
int const nmax = 100;
char line[5 + nmax];
int sol[5 + nmax];
void precompute(){
  for(int i = 1 ; i <= 100 ;i++){
    sol[i] = (sol[i - 1] + lastcif(i , i)) % 10;
  }
}
int main()
{
  precompute();
  int t , n;
  in>>t;
  line[0] = '0';
  for(int testcase = 1 ;testcase <= t ;testcase++){
    in>>(line + 1);
    n = strlen(line + 1);
    int k = (line[n - 1] - '0') * 10 + (line[n] - '0');
    out<<sol[k]<<'\n';
  }
  return 0;
}