#include <bits/stdc++.h> #define M 110 #define pb push_back #define mp make_pair #define st first #define nd second using namespace std; char s[M]; long long pot[M],a,b; bool prime(long long x){ if(x==1){ return false; } for(int i=2; i*i<=x; i++){ if(x%(long long)i==0){ return false; } } return true; } int main(){ pot[0]=1; for(int i=1; i<=14; i++){ pot[i]=pot[i-1]*10LL; } scanf("%s",&s); int m=strlen(s); for(int i=0; i<m; i++){ a=a*10LL+(long long)(s[i]-'0'); } for(int i=0; i<m-1; i++){ b=b*10LL+(long long)(s[i]-'0'); a%=pot[m-i-1]; if(s[i+1]!='0'&&prime(a)&&prime(b)){ puts("TAK"); return 0; } } puts("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 | #include <bits/stdc++.h> #define M 110 #define pb push_back #define mp make_pair #define st first #define nd second using namespace std; char s[M]; long long pot[M],a,b; bool prime(long long x){ if(x==1){ return false; } for(int i=2; i*i<=x; i++){ if(x%(long long)i==0){ return false; } } return true; } int main(){ pot[0]=1; for(int i=1; i<=14; i++){ pot[i]=pot[i-1]*10LL; } scanf("%s",&s); int m=strlen(s); for(int i=0; i<m; i++){ a=a*10LL+(long long)(s[i]-'0'); } for(int i=0; i<m-1; i++){ b=b*10LL+(long long)(s[i]-'0'); a%=pot[m-i-1]; if(s[i+1]!='0'&&prime(a)&&prime(b)){ puts("TAK"); return 0; } } puts("NIE"); return 0; } |