#include <bits/stdc++.h>
bool isPrime(long long a){
if (a <= 1)
return false;
for (int i = 2; i * i <= a; i++){
if (a % i == 0)
return false;
}
return true;
}
int main(){
std::ios_base::sync_with_stdio(0);
std::cin.tie(NULL);
long long a;
std::cin >> a;
bool wynik = false;
long long x = a % 10;
long long y = a / 10;
long long dziesiatki = 10;
while (y > 0 && !wynik){
if (isPrime(x) && isPrime(y))
wynik = true;
else{
while (y % 10 == 0){
y /= 10;
dziesiatki *= 10;
}
x += (y%10) * dziesiatki;
dziesiatki *= 10;
y /= 10;
}
}
(wynik) ? std::cout << "TAK\n" : std::cout << "NIE\n";
}
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 | #include <bits/stdc++.h> bool isPrime(long long a){ if (a <= 1) return false; for (int i = 2; i * i <= a; i++){ if (a % i == 0) return false; } return true; } int main(){ std::ios_base::sync_with_stdio(0); std::cin.tie(NULL); long long a; std::cin >> a; bool wynik = false; long long x = a % 10; long long y = a / 10; long long dziesiatki = 10; while (y > 0 && !wynik){ if (isPrime(x) && isPrime(y)) wynik = true; else{ while (y % 10 == 0){ y /= 10; dziesiatki *= 10; } x += (y%10) * dziesiatki; dziesiatki *= 10; y /= 10; } } (wynik) ? std::cout << "TAK\n" : std::cout << "NIE\n"; } |
English