fork download
  1. #include <iostream>
  2. #include <math.h>
  3.  
  4. using namespace std;
  5. char isprime(long n)
  6. {
  7. long i, j;
  8. if (n < 4) return 1;
  9. if ((n & 1) == 0) return 0; //even
  10. j = (long)sqrt((double)n);
  11. for (i = 3; i <= j; i += 2)
  12. if (n%i == 0) return 0;
  13. return 1;
  14. }
  15. int main() {
  16. // your code goes here
  17. char a[255];
  18. char i = 0;
  19. long maxprimenow = 0;
  20. long check = 0;
  21. char round = 0;
  22. while (cin >> a) {
  23. if (a[0] = 0) {
  24. break;
  25. }
  26. else {
  27. cout << a << endl;
  28. while (a[i] != NULL) {
  29. check = check * 10 + a[i];
  30. if (check < 100000) {
  31. if (isprime(check)) {
  32. if (maxprimenow < check) { maxprimenow = check; }
  33. }
  34. }
  35. else {
  36. check = 0;
  37. round++;
  38. i = round;
  39. }
  40. i++;
  41. }
  42. }
  43. }
  44. return 0;
  45. }
Success #stdin #stdout 0s 4412KB
stdin
11245
91321150448
1226406
0
stdout