Pagini recente » Cod sursa (job #438660) | Cod sursa (job #461466) | Cod sursa (job #263495) | Cod sursa (job #472844) | Cod sursa (job #2460302)
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
using namespace std;
int utszj(int x)
{
if(x%10==1) return 1;
if(x%10==2 and x%4==2) return 4;
if(x%10==2 and x%4==0) return 6;
if(x%10==3 and x%4==1) return 3;
if(x%10==3 and x%4==3) return 7;
if(x%10==4) return 6;
if(x%10==5) return 5;
if(x%10==6) return 6;
if(x%10==7 and x%4==1) return 7;
if(x%10==7 and x%4==3) return 3;
if(x%10==8 and x%4==2) return 4;
if(x%10==8 and x%4==0) return 6;
if(x%10==9) return 9;
if(x%10==0) return 0;
}
int utszj_2(int a)
{
if(a==1) return 1;
long long akt = 0;
akt = pow(a, a);
akt%=10;
return (akt + utszj_2(a-1));
}
int main()
{
ifstream f("cifra.in");
ofstream g("cifra.out");
int t;
f>>t;
//cout<<t<<endl;
string s;
getline(f, s);
int m, ered;
int ered2;
for(int i=1; i<=t; i++)
{
getline(f, s);
//cout<<s<<endl;
if(s.length()>=2){
s=s.substr(s.length()-2, 2);
m=(s[0]-48)*10+(s[1]-48);
}
else m=s[0]-48;
//brut force*/
/*ered = 0;
for(int i=m; i>=1; i--)
{
ered += utszj(i);
ered%=10;
}*/
//g<<"brut force "<<ered<<" ";
//cout<<"szam = "<<n<<endl;
ered = 0;
ered+=m/20*4;
ered%=10;
while(m%20!=0)
{
ered+=utszj(m);
//cout<<n<<" "<<utszj(n)<<endl;
//cout<<"ered = "<<ered<<endl;
ered%=10;
m--;
}
g<<ered<<endl;
//brut force
}
return 0;
}