Cod sursa(job #1239212)
| Utilizator | Data | 8 octombrie 2014 16:17:19 | |
|---|---|---|---|
| Problema | Cifra | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.7 kb |
#include <fstream>
#include <cstring>
#define lmax 105
using namespace std;
ifstream f("cifra.in");
ofstream g("cifra.out");
int i;
int v[lmax];
char s[lmax];
inline int preproc(int x)
{
int p=x,xx=1;
while (p)
if (p%2)
{
xx*=x;
x=(x*x)%10;
p/=2;
}
else
{
x=(x*x)%10;
p/=2;
}
return xx;
}
int main()
{
int t,x;
for (i=1;i<100;i++)
v[i]=(v[i-1]+preproc(i))%10;
f>>t;
for (i=1;i<=t;i++)
{
f>>s;
x=strlen(s)-1;
g<<v[(x>1?(s[x-1]-'0'):0)*10+s[x]-'0']<<'\n';
}
f.close();
g.close();
}
