fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4. // Hàm tà đạo :)
  5. bool isPrime(int n) {
  6. if (n <= 1) return false;
  7. if (n <= 3) return true;
  8. if (n % 2 == 0 || n % 3 == 0) return false;
  9. for (int i = 5; i * i <= n; i += 6) {
  10. if (n % i == 0 || n % (i + 2) == 0)
  11. return false;
  12. }
  13. return true;
  14. }
  15. signed main() {
  16. string T;
  17. cin >> T;
  18. int a = T.length();
  19. int nguyenthanhluu = -1;
  20. for (int i = 0; i < a; i++) {
  21. int ngu = 0;
  22. for (int j = i; j < a; j++) {
  23. if (T[j] < '0' || T[j] > '9') break;
  24. ngu = ngu * 10 + (T[j] - '0');
  25. if (ngu >= 1e8) break;
  26. if (isPrime(ngu) ) {
  27. nguyenthanhluu = max(nguyenthanhluu,ngu);
  28. }
  29. }
  30. }
  31. cout << nguyenthanhluu << endl;
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 5308KB
stdin
Test1234#password5426 
stdout
23