Advertisement
Josif_tepe

Untitled

Nov 16th, 2021
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int rec(int number, int i) {
  5.     if(i > number) {
  6.         return 0;
  7.     }
  8.     if(number % i == 0) {
  9.         return rec(number, i + 1) + 1;
  10.     }
  11.     else {
  12.         return rec(number, i + 1);
  13.     }
  14. }
  15. int main()
  16. {
  17.     int n;
  18.     cin >> n;
  19.     cout << rec(n, 1) << endl;
  20.     return 0;
  21. }
  22. /*
  23.  rec(5, 1) = rec(5, 2) + 1 = 1 + 1 = 2
  24.  rec(5, 2) = rec(5, 3) = 1
  25.  rec(5, 3) = rec(5, 4) = 1
  26.  rec(5, 4) = rec(5, 5) = 1
  27.  rec(5, 5) = rec(5, 6) + 1  = 0 + 1 = 1
  28.  rec(5, 6) = 0
  29.  
  30.  **/
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement