Advertisement
fahimkamal63

Twisted Prime Number

Jun 13th, 2019
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cmath>
  4. using namespace std;
  5.  
  6. int rever(int n){
  7.     int a = 0;
  8.     while(n){
  9.         a *= 10;
  10.         int k = n % 10;
  11.         a += k;
  12.         n /= 10;
  13.     }
  14.     return a;
  15. }
  16.  
  17. bool prime(int a){
  18.     for(int i = 2; i <= sqrt(a); i++){
  19.         if(!(a % i)) return false;
  20.     }
  21.     return true;
  22. }
  23.  
  24. bool twist(int a){
  25.     int n = rever(a);
  26.     if(prime(a) && prime(n)) return true;
  27.     return false;
  28. }
  29.  
  30. int main(){
  31.     int t; scanf("%d", &t);
  32.     while(t--){
  33.         int n; scanf("%d", &n);
  34.         (twist(n)) ? printf("Yes\n") : printf("No\n");
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement