#include<iostream>
#define M 1000000007
using namespace std;
char c;
long long int a,pot=29,ilepot,ostpot=1,it,fhasz1,fhasz2,pot2=31,fhasz3,fhasz4;
long long potega(long long a, unsigned int n)
{
long long w = 1;
while(n>0)
{
if (n%2 == 1)
w *= a;
a*= a;
a%=M;
w%=M;
n/=2;
}
return w;
}
int main()
{
unsigned int n;
long long a;
cin>>it;
if(it%2==0)
{
for(int i=1; i<=it/2; i++)
{
cin>>c;
fhasz1+=(((int)c%96)*pot)%M;
fhasz1%=M;
fhasz3+=(((int)c%96)*pot2)%M;
fhasz3%=M;
pot=(pot*29)%M;
pot2=(pot2*31)%M;
ilepot++;
}
pot=(potega(29,ilepot))%M;
pot2=(potega(31,ilepot))%M;
for(int i=1; i<=it/2; i++)
{
cin>>c;
fhasz2+=(((int)c%96)*pot)%M;
fhasz2%=M;
fhasz4+=(((int)c%96)*pot2)%M;
fhasz4%=M;
ilepot--;
pot=(potega(29,ilepot))%M;
pot2=(potega(31,ilepot))%M;
}
}
if(it%2==1)
{
for(int i=1; i<=it/2; i++)
{
cin>>c;
fhasz1+=(((int)c%96)*pot)%M;
fhasz1%=M;
fhasz3+=(((int)c%96)*pot2)%M;
fhasz3%=M;
pot=(pot*29)%M;
pot2=(pot2*31)%M;
ilepot++;
}
cin>>c;
pot=(potega(29,ilepot))%M;
pot2=(potega(31,ilepot))%M;
for(int i=1; i<=it/2; i++)
{
cin>>c;
fhasz2+=(((int)c%96)*pot)%M;
fhasz2%=M;
fhasz4+=(((int)c%96)*pot2)%M;
fhasz4%=M;
ilepot--;
pot=(potega(29,ilepot))%M;
pot2=(potega(31,ilepot))%M;
}
}
//cout<<fhasz1<<endl<<fhasz2<<endl<<fhasz3<<endl<<fhasz4<<endl;
if(fhasz1==fhasz2||fhasz3==fhasz4)
cout<<"TAK";
else cout<<"NIE";
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | #include<iostream> #define M 1000000007 using namespace std; char c; long long int a,pot=29,ilepot,ostpot=1,it,fhasz1,fhasz2,pot2=31,fhasz3,fhasz4; long long potega(long long a, unsigned int n) { long long w = 1; while(n>0) { if (n%2 == 1) w *= a; a*= a; a%=M; w%=M; n/=2; } return w; } int main() { unsigned int n; long long a; cin>>it; if(it%2==0) { for(int i=1; i<=it/2; i++) { cin>>c; fhasz1+=(((int)c%96)*pot)%M; fhasz1%=M; fhasz3+=(((int)c%96)*pot2)%M; fhasz3%=M; pot=(pot*29)%M; pot2=(pot2*31)%M; ilepot++; } pot=(potega(29,ilepot))%M; pot2=(potega(31,ilepot))%M; for(int i=1; i<=it/2; i++) { cin>>c; fhasz2+=(((int)c%96)*pot)%M; fhasz2%=M; fhasz4+=(((int)c%96)*pot2)%M; fhasz4%=M; ilepot--; pot=(potega(29,ilepot))%M; pot2=(potega(31,ilepot))%M; } } if(it%2==1) { for(int i=1; i<=it/2; i++) { cin>>c; fhasz1+=(((int)c%96)*pot)%M; fhasz1%=M; fhasz3+=(((int)c%96)*pot2)%M; fhasz3%=M; pot=(pot*29)%M; pot2=(pot2*31)%M; ilepot++; } cin>>c; pot=(potega(29,ilepot))%M; pot2=(potega(31,ilepot))%M; for(int i=1; i<=it/2; i++) { cin>>c; fhasz2+=(((int)c%96)*pot)%M; fhasz2%=M; fhasz4+=(((int)c%96)*pot2)%M; fhasz4%=M; ilepot--; pot=(potega(29,ilepot))%M; pot2=(potega(31,ilepot))%M; } } //cout<<fhasz1<<endl<<fhasz2<<endl<<fhasz3<<endl<<fhasz4<<endl; if(fhasz1==fhasz2||fhasz3==fhasz4) cout<<"TAK"; else cout<<"NIE"; return 0; } |
English