fork download
  1. #include <iostream>
  2. using namespace std;
  3. double n;
  4. int check(int x){
  5. for(int i = 2; i * i <= x; i++){
  6. if(x % i == 0){
  7. return 0;
  8. }
  9. }
  10. return 1;
  11. }
  12. int main() {
  13. cin >> n;
  14. for(int i =n - 1; i >= 1; i--){
  15. if(check(i) == 1){
  16. cout << i << endl;
  17. //return 0;
  18. }
  19. }
  20. cout << n;
  21. return 0;
  22. }
Success #stdin #stdout 0s 3472KB
stdin
50
stdout
47
43
41
37
31
29
23
19
17
13
11
7
5
3
2
1
50