#include <iostream> #include <stdio.h> using namespace std; long long szybkie(long long a,long long w,long long mod) { if(w==0) return 1; if(w%2==1) return (a*(szybkie(a,(w-1)/2,mod))*(szybkie(a,(w-1)/2,mod)))%mod; return (szybkie(a,(w-1)/2,mod))*(szybkie(a,(w-1)/2,mod))%mod; } long long hasz,hasz2,hasz3,hasz4,p=1,a=1; int n,x=29,z=0; char c; int main() { std::ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); cin>>n; if(n>0) { if(n%2==0) { for(int i=1; i<=(n/2); i++) { cin>>c; hasz3+=((int)c*p)%1000696969; hasz3%=1000696969; hasz+=((int)c*p)%1000000007; hasz%=1000000007; p=(p*x)%1000000007; } for(int i=1; i<=(n/2); i++) { cin>>c; p=szybkie(x,n/2-(i),1000696969)%1000696969; hasz4+=((int)c*p)%1000696969; hasz4%=1000696969; p=szybkie(x,n/2-(i),1000000007)%1000000007; hasz2+=((int)c*p)%1000000007; hasz2%=1000000007; } } if(n%2==1) { for(int i=1; i<=(n/2); i++) { cin>>c; hasz3+=((int)c*p)%1000696969; hasz3%=1000696969; hasz+=((int)c*p)%1000000007; hasz%=1000000007; p=(p*x)%1000000007; } p=1; cin>>c; for(int i=1; i<=(n/2); i++) { cin>>c; p=szybkie(x,n/2-(i),1000696969)%1000696969; hasz4+=((int)c*p)%1000696969; hasz4%=1000696969; p=szybkie(x,n/2-(i),1000000007)%1000000007; hasz2+=((int)c*p)%1000000007; hasz2%=1000000007; } } if(hasz==hasz2&&hasz3==hasz4) cout<<"TAK"; else cout<<"NIE"; return 0; } else if(n==0) { cout<<"NIE"; return 0; } 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 | #include <iostream> #include <stdio.h> using namespace std; long long szybkie(long long a,long long w,long long mod) { if(w==0) return 1; if(w%2==1) return (a*(szybkie(a,(w-1)/2,mod))*(szybkie(a,(w-1)/2,mod)))%mod; return (szybkie(a,(w-1)/2,mod))*(szybkie(a,(w-1)/2,mod))%mod; } long long hasz,hasz2,hasz3,hasz4,p=1,a=1; int n,x=29,z=0; char c; int main() { std::ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); cin>>n; if(n>0) { if(n%2==0) { for(int i=1; i<=(n/2); i++) { cin>>c; hasz3+=((int)c*p)%1000696969; hasz3%=1000696969; hasz+=((int)c*p)%1000000007; hasz%=1000000007; p=(p*x)%1000000007; } for(int i=1; i<=(n/2); i++) { cin>>c; p=szybkie(x,n/2-(i),1000696969)%1000696969; hasz4+=((int)c*p)%1000696969; hasz4%=1000696969; p=szybkie(x,n/2-(i),1000000007)%1000000007; hasz2+=((int)c*p)%1000000007; hasz2%=1000000007; } } if(n%2==1) { for(int i=1; i<=(n/2); i++) { cin>>c; hasz3+=((int)c*p)%1000696969; hasz3%=1000696969; hasz+=((int)c*p)%1000000007; hasz%=1000000007; p=(p*x)%1000000007; } p=1; cin>>c; for(int i=1; i<=(n/2); i++) { cin>>c; p=szybkie(x,n/2-(i),1000696969)%1000696969; hasz4+=((int)c*p)%1000696969; hasz4%=1000696969; p=szybkie(x,n/2-(i),1000000007)%1000000007; hasz2+=((int)c*p)%1000000007; hasz2%=1000000007; } } if(hasz==hasz2&&hasz3==hasz4) cout<<"TAK"; else cout<<"NIE"; return 0; } else if(n==0) { cout<<"NIE"; return 0; } return 0; } |