fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. //receive input
  7. int testCase; cin >> testCase;
  8. int* arr = new int[testCase];
  9. for (int i = 0; i < testCase; i++)
  10. {
  11. cin >> arr[i];
  12. }
  13.  
  14. //find the max value among those inputs.
  15. int max = 0;
  16. for (int i = 0; i < testCase; i++)
  17. {
  18. if (arr[i] > max)
  19. {
  20. max = arr[i];
  21. }
  22. }
  23.  
  24. //find the N
  25. int temp = 2;
  26. bool canEscape = false;
  27. while (true)
  28. {
  29. for (int i = 0; i < testCase; i++)
  30. {
  31. if (temp % arr[i] != 0)
  32. {
  33. break;
  34. }
  35. else if (i == testCase-1 && temp > max) //if examined with all numbers && N != temp
  36. {
  37. cout << temp;
  38. canEscape = true; //to escape while loop.
  39. }
  40. }
  41. if (canEscape)
  42. break;
  43. temp++;
  44. }
  45.  
  46. delete []arr;
  47. return 0;
  48. }
Success #stdin #stdout 0.01s 5280KB
stdin
1
3
stdout
6