#include <cstdio>
#define PRIME 877207032516559
#define ONE 0
#define TWO 1
#define PRI 2
#define POW 3
long long arr[6][4] = {};
int main() {
int temp;
char c;
scanf("%d", &temp);
arr[0][PRI] = 2;
arr[1][PRI] = 3;
arr[2][PRI] = 5;
arr[3][PRI] = 7;
arr[4][PRI] = 11;
arr[5][PRI] = 13;
for (int i=0; i<6; ++i)
arr[i][POW] = 1;
while((c=getchar()) != EOF) {
if (c == ' ' || c == '\n')
continue;
for (int i=0; i<6; ++i) {
arr[i][ONE] += c * arr[i][POW];
arr[i][TWO] *= arr[i][PRI];
arr[i][TWO] += c;
arr[i][POW] *= arr[i][PRI];
arr[i][ONE] %= PRIME;
arr[i][TWO] %= PRIME;
arr[i][POW] %= PRIME;
}
}
int tak = 1;
for (int i=0; i<6; ++i) {
if (arr[i][ONE] != arr[i][TWO])
tak = 0;
}
if (tak)
printf("TAK\n");
else
printf("NIE\n");
return 0;
}
//
//int main() {
// int temp;
// char c;
// scanf("%d", &temp);
// long long one = 0;
// long long two = 0;
// long long pow = 1;
// while((c = getchar()) != EOF) {
// if (c == ' ' || c == '\n')
// continue;
// one += c * pow;
// two <<= 1;
// two += c;
//
// pow <<=1;
// printf("\n%lld %lld\n", one, two);
// one %= PRIME;
// two %= PRIME;
// pow %= PRIME;
// printf("%lld %lld\n", one, two);
// }
//
// if (one == two)
// printf("TAK\n");
// else
// printf("NIE\n");
//
// 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 <cstdio> #define PRIME 877207032516559 #define ONE 0 #define TWO 1 #define PRI 2 #define POW 3 long long arr[6][4] = {}; int main() { int temp; char c; scanf("%d", &temp); arr[0][PRI] = 2; arr[1][PRI] = 3; arr[2][PRI] = 5; arr[3][PRI] = 7; arr[4][PRI] = 11; arr[5][PRI] = 13; for (int i=0; i<6; ++i) arr[i][POW] = 1; while((c=getchar()) != EOF) { if (c == ' ' || c == '\n') continue; for (int i=0; i<6; ++i) { arr[i][ONE] += c * arr[i][POW]; arr[i][TWO] *= arr[i][PRI]; arr[i][TWO] += c; arr[i][POW] *= arr[i][PRI]; arr[i][ONE] %= PRIME; arr[i][TWO] %= PRIME; arr[i][POW] %= PRIME; } } int tak = 1; for (int i=0; i<6; ++i) { if (arr[i][ONE] != arr[i][TWO]) tak = 0; } if (tak) printf("TAK\n"); else printf("NIE\n"); return 0; } // //int main() { // int temp; // char c; // scanf("%d", &temp); // long long one = 0; // long long two = 0; // long long pow = 1; // while((c = getchar()) != EOF) { // if (c == ' ' || c == '\n') // continue; // one += c * pow; // two <<= 1; // two += c; // // pow <<=1; // printf("\n%lld %lld\n", one, two); // one %= PRIME; // two %= PRIME; // pow %= PRIME; // printf("%lld %lld\n", one, two); // } // // if (one == two) // printf("TAK\n"); // else // printf("NIE\n"); // // return 0; //} |
English