fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const int N = 1e6;
  4.  
  5. bool prime_poo(long long prime){
  6. if (prime <= 1)return false;
  7. for (long long p = 2; p < prime; p++){
  8. if (prime % p == 0){
  9. return false;
  10. }
  11. }
  12. return true;
  13. }
  14.  
  15. signed main(){
  16. ios::sync_with_stdio(false);
  17.  
  18. long long n, a[N];
  19. string s;
  20. cin >> n;
  21. for (long long i = 0; i < n; i++){
  22. cin >> a[i];
  23. long long b = a[i];
  24. while(b > 0){
  25. if (prime_poo(b) == false){
  26. break;
  27. }
  28. else if (b/10 == 0){
  29. cout << a[i];
  30. if (i+1 != n){
  31. cout << endl;
  32. }
  33. break;
  34. }
  35. else {
  36. b/=10;
  37. }
  38. }
  39. }
  40. }
  41.  
Success #stdin #stdout 0.01s 5288KB
stdin
5
2 13 7 123 53
stdout
2
7
53