Advertisement
Josif_tepe

Untitled

Oct 17th, 2023
717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int broj_na_deliteli(int n, int idx) {
  6.     if(idx > n) {
  7.         return 0;
  8.     }
  9.     bool deliv = ((n % idx) == 0);
  10.    
  11.     return broj_na_deliteli(n, idx + 1) + deliv;
  12. }
  13. int k_deliv(int x, int idx, int k) {
  14.     if(idx < x - k or idx == 0) {
  15.         return 1;
  16.     }
  17.     if(broj_na_deliteli(idx, 1) >= broj_na_deliteli(x, 1)) {
  18.         return 0;
  19.     }
  20.     return k_deliv(x, idx - 1, k);
  21. }
  22. int sum(int a, int b, int k) {
  23.     if(a > b) {
  24.         return 0;
  25.     }
  26.     int dodadi = 0;
  27.     if(k_deliv(a, a - 1, k)) {
  28.         dodadi = a;
  29.     }
  30.     return sum(a + 1, b, k) + dodadi;
  31. }
  32.                              
  33. int main() {
  34.     int a, b, k;
  35.     cin >> a >> b >> k;
  36.     cout << sum(a, b, k) << endl;
  37.     return 0;
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement