Advertisement
Josif_tepe

Untitled

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