#include<bits/stdc++.h>
#define M 1000000007
using namespace std;
int n;
char s;
long long hasz1, hasz2;
long long pot[100001];
void potegi()
{
pot[0] = 1;
if(n/2>100000)
{
for(int i = 1; i <= n/2;++i)
{
pot[i] = (pot[i - 1] * 37) % M;
}
}
else
{
for(int i = 1; i <= 100000;++i)
{
pot[i] = (pot[i - 1] * 37) % M;
}
}
}
long long potega(int x)
{
long long wynik=1;
while(x-100000>0)
{
wynik=(wynik*pot[100000])%M;
x-=100000;
}
return (wynik*pot[x])%M;
}
int main()
{
scanf("%d",&n);
potegi();
for(int i=1;i<=n/2;++i)
{
cin >> s;
hasz1=(hasz1+((s*potega(i-1))%M))%M;
//cout << "\n" << hasz1;
}
if(n%2==1)
{
scanf("%c",&s);
}
for(int i=1;i<=n/2;++i)
{
cin >> s;
hasz2=(hasz2+((s*potega((n/2)-i))%M))%M;
//cout << "\n" << hasz2;
}
if(hasz1==hasz2)
{
printf("TAK");
}
else
{
printf("NIE");
}
}
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 | #include<bits/stdc++.h> #define M 1000000007 using namespace std; int n; char s; long long hasz1, hasz2; long long pot[100001]; void potegi() { pot[0] = 1; if(n/2>100000) { for(int i = 1; i <= n/2;++i) { pot[i] = (pot[i - 1] * 37) % M; } } else { for(int i = 1; i <= 100000;++i) { pot[i] = (pot[i - 1] * 37) % M; } } } long long potega(int x) { long long wynik=1; while(x-100000>0) { wynik=(wynik*pot[100000])%M; x-=100000; } return (wynik*pot[x])%M; } int main() { scanf("%d",&n); potegi(); for(int i=1;i<=n/2;++i) { cin >> s; hasz1=(hasz1+((s*potega(i-1))%M))%M; //cout << "\n" << hasz1; } if(n%2==1) { scanf("%c",&s); } for(int i=1;i<=n/2;++i) { cin >> s; hasz2=(hasz2+((s*potega((n/2)-i))%M))%M; //cout << "\n" << hasz2; } if(hasz1==hasz2) { printf("TAK"); } else { printf("NIE"); } } |
English