Advertisement
myloyo

8.1.3-3 рекурсия

May 18th, 2023 (edited)
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <fstream>
  4. using namespace std;
  5.  
  6. int del(int n, int s = 1) {
  7.     if (s <= n) {
  8.         if (n % s == 0) {
  9.             return s + del(n, s + 1);
  10.         }
  11.         else {
  12.             return del(n, s + 1);
  13.         }
  14.     }
  15.     else { return 0; }
  16. }
  17.  
  18. int main() {
  19.     int a, b;
  20.     cin >> a >> b;
  21.     int c = 1;
  22.     for (int i = a; i <= b; i++) {
  23.         c = max(c, del(i));
  24.     }
  25.     for (int i = a; i <= b; i++) {
  26.         if (del(i) == c) {
  27.             cout << i << " ";
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement