fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. typedef long double ld;
  6. typedef pair<ll, ll> pll;
  7. typedef pair<int, int> pii;
  8. typedef pair<long double, long double> pdd;
  9. typedef vector<vector<ll> > matrix;
  10. #define fi first
  11. #define se second
  12. #define mp make_pair
  13. #define pb push_back
  14. #define popb pop_back
  15. #define pf push_front
  16. #define popf pop_front
  17. template <class T> inline T sqr(T x) { return x * x; };
  18. template <class T> inline bool maximize(T& a, T b) { return (a < b) ? a = b, true : false; }
  19. template <class T> inline bool minimize(T& a, T b) { return (a > b) ? a = b, true : false; }
  20.  
  21. string lowcase = "abcdefghijklmnopqrstuvwxyz";
  22. string upcase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  23. string number = "0123456789";
  24. int dx[] = {0, 0, -1, 1};
  25. int dy[] = {-1, 1, 0, 0};
  26. const ll pd = 1e9 + 7;
  27. const ll oo = 9e18 + 1;
  28. const int MX = 200100, LIM = 1e6;
  29. bool ktsnt(int n) {
  30. if(n < 2) return false;
  31. if(n == 2) return true;
  32. for(int i=2; i*i<=n; i++)
  33. if(n % i == 0) return false;
  34. return true;
  35. }
  36. bool isNumber(char ch) {
  37. return (ch >= '0' && ch <= '9');
  38. }
  39. int main (){
  40. string s; cin >> s;
  41. int ans = 0;
  42. for(int i=0; i<s.size(); i++) {
  43. if(isNumber(s[i])) {
  44. string so = "";
  45. int j = i;
  46. while(j < s.size() && isNumber(s[j])) {
  47. so += s[j];
  48. j++;
  49. }
  50.  
  51. int num = 0, sz = so.size();
  52. for(int i=sz-1; i>=0; i--)
  53. num += pow(10, sz-i-1)*(so[i]-'0');
  54.  
  55. if(ktsnt(num)) ans = max(ans, num);
  56. i = j-1;
  57. }
  58. }
  59. cout << ans << '\n';
  60. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
0