fork download
  1. #include<iostream>
  2.  
  3. bool isPrime(int x) {
  4. if(x <= 3) return x > 1;
  5. if(x % 2 == 0 || x % 3 == 0) return false;
  6. for(int i = 5; i * i <= x; i += 6) {
  7. if(x % i == 0 || x % (i + 2) == 0) return false;
  8. }
  9. return true;
  10. }
  11.  
  12. int main() {
  13. freopen("SNT.INP", "r", stdin);
  14. freopen("SNT.OUT", "w", stdout);
  15.  
  16. std::string S;
  17. std::cin >> S;
  18.  
  19. S = S + 'a';
  20. int num = 0, res = -1;
  21.  
  22. for(int i = 0; i < S.length(); ++i) {
  23. if('0' <= S[i] && S[i] <= '9') {
  24. num = num * 10 + (S[i] - '0');
  25. }
  26. else {
  27. if(isPrime(num)) res = std::max(res, num);
  28. num = 0;
  29. }
  30. }
  31.  
  32. std::cout << res;
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty