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