fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. bool is_prime(int n) {
  7. if (n <= 1) return false;
  8. if (n <= 3) return true;
  9. if (n % 2 == 0 || n % 3 == 0) return false;
  10. for (int i = 5; i * i <= n; i += 6) {
  11. if (n % i == 0 || n % (i + 2) == 0) return false;
  12. }
  13. return true;
  14. }
  15.  
  16. bool is_perfect_square(int x) {
  17. int sqrt_x = sqrt(x);
  18. return sqrt_x * sqrt_x == x;
  19. }
  20.  
  21. bool is_fibonacci(int n) {
  22. return is_perfect_square(5 * n * n + 4) || is_perfect_square(5 * n * n - 4);
  23. }
  24.  
  25. string escape_cave(int x) {
  26. if (to_string(x).length() <= 2) {
  27. return "Oh my God. Alibaba Died.";
  28. } else if (is_prime(x) && is_fibonacci(x)) {
  29. return "Hurray... Alibaba Escaped...";
  30. } else {
  31. return "Oh my God. Alibaba Died.";
  32. }
  33. }
  34.  
  35. int main() {
  36. int x;
  37. cin >> x;
  38. cout << escape_cave(x) << endl;
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 5300KB
stdin
45
stdout
Oh my God. Alibaba Died.