Cod sursa(job #1811607)

Utilizator 41xofSav Cristian-Theodor 41xof Data 21 noiembrie 2016 13:19:43
Problema Cifra Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include<fstream>
#include<iostream>
#include<math.h>
#include<cstring>

using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");

int c2(long long x, long long k){
    if(k%4==0) return x*x*x*x%10;
    if(k%4==1) return x%10;
    if(k%4==2) return x*x%10;
    if(k%4==3) return x*x*x%10;
}

int main(){
    long long T;
    char n[105];
    int c;
    char denis;
    f>>T;
    f.get(denis);
    for(long long j=1;j<=T;j++){
        f.getline(n,105);
        long long s=0;
        c=strlen(n);
        cout<<c<<" ";
        int v;
        if(c>1)
            v=(n[c-2]-'0')*10+(n[c-1]-'0');
        else v=(n[c-1]-'0');
        for(long long i=1;i<=v;i++){
            int u=i%10;
            s=s+c2(u,i);s=s%10;
        }
        g<<s%10<<endl;
    }
}