Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int rec(int number, int i) {
- if(i > number) {
- return 0;
- }
- if(number % i == 0) {
- return rec(number, i + 1) + 1;
- }
- else {
- return rec(number, i + 1);
- }
- }
- int main()
- {
- int n;
- cin >> n;
- cout << rec(n, 1) << endl;
- return 0;
- }
- /*
- rec(5, 1) = rec(5, 2) + 1 = 1 + 1 = 2
- rec(5, 2) = rec(5, 3) = 1
- rec(5, 3) = rec(5, 4) = 1
- rec(5, 4) = rec(5, 5) = 1
- rec(5, 5) = rec(5, 6) + 1 = 0 + 1 = 1
- rec(5, 6) = 0
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement