Advertisement
Josif_tepe

Untitled

Nov 11th, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. using namespace std;
  5.  
  6. int number_of_divisors(int n, int i = 1) {
  7.     if(i == n) {
  8.         return 1;
  9.     }
  10.     int is_divisor = 0;
  11.     if(n % i == 0) {
  12.         is_divisor = 1;
  13.     }
  14.     return number_of_divisors(n, i + 1) + is_divisor;
  15. }
  16. int is_k(int n, int k, int N) {
  17.     if(n == 0) {
  18.         return 1;
  19.     }
  20.     if(k == 0) {
  21.         return 1;
  22.     }
  23.     if(number_of_divisors(N) <= number_of_divisors(n)) {
  24.         return 0;
  25.     }
  26.     return is_k(n - 1, k - 1, N);
  27.    
  28. }
  29. int sum(int a, int b, int k) {
  30.     if(a > b) {
  31.         return 0;
  32.     }
  33.     int number = 0;
  34.     if(is_k(a - 1, k, a)) {
  35.         number = a;
  36.     }
  37.     return sum(a + 1, b, k) + number;
  38. }
  39. int main() {
  40.    
  41.     int a, b;
  42.     cin >> a >> b;
  43.    
  44.     int k;
  45.     cin >> k;
  46.     cout << sum(a, b, k) << endl;
  47.    
  48.    
  49.     return 0;
  50. }
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement