#include <stdio.h> #define ll long long using namespace std; ll horner[5], hasz[6], pot[]={1, 1, 1, 1, 1, 0}; ll p = 53; int n; int ans; ll mod[]={1059488237, 1014249527, 1029486503, 1011113261, 1039285453}; char c; void fs(int &liczba) { char c = 0; liczba = 0; while(c < 33) c = getchar_unlocked(); do { liczba = (liczba << 1) + (liczba << 3) + c - '0'; c = getchar_unlocked(); } while(c > 33); } main() { fs(n); c = getchar_unlocked(); while(c >= 'a' && c <= 'z') { c -= 'a'-1; for (int i = 0; i <= 2; i++) { horner[i] = ((horner[i]*p)+c)%mod[i]; hasz[i] = (hasz[i] + (c * pot[i]))%mod[i]; pot[i] = (pot[i]*p)%mod[i]; } c = getchar_unlocked(); } for (int i = 0; i <= 2; i++) { if (horner[i]==hasz[i]) ans++; } if (ans==3) { puts("TAK"); } else puts("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 | #include <stdio.h> #define ll long long using namespace std; ll horner[5], hasz[6], pot[]={1, 1, 1, 1, 1, 0}; ll p = 53; int n; int ans; ll mod[]={1059488237, 1014249527, 1029486503, 1011113261, 1039285453}; char c; void fs(int &liczba) { char c = 0; liczba = 0; while(c < 33) c = getchar_unlocked(); do { liczba = (liczba << 1) + (liczba << 3) + c - '0'; c = getchar_unlocked(); } while(c > 33); } main() { fs(n); c = getchar_unlocked(); while(c >= 'a' && c <= 'z') { c -= 'a'-1; for (int i = 0; i <= 2; i++) { horner[i] = ((horner[i]*p)+c)%mod[i]; hasz[i] = (hasz[i] + (c * pot[i]))%mod[i]; pot[i] = (pot[i]*p)%mod[i]; } c = getchar_unlocked(); } for (int i = 0; i <= 2; i++) { if (horner[i]==hasz[i]) ans++; } if (ans==3) { puts("TAK"); } else puts("NIE"); } |