Advertisement
Josif_tepe

Untitled

Apr 6th, 2022
1,069
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None
  1. #include <iostream>
  2. #include <cstring>
  3. #include <cmath>
  4. #include <math.h>
  5. #include <vector>
  6. #include <queue>
  7. using namespace std;
  8.  
  9. int num_of_divisors_of_x(int x, int i) {
  10.     if(i > x) {
  11.         return 0;
  12.     }
  13.     int divisor = 0;
  14.     if(x % i == 0) {
  15.         divisor = 1;
  16.     }
  17.     return num_of_divisors_of_x(x, i + 1) + divisor;
  18. }
  19.  
  20. int k_deliv(int A, int B) {
  21.     if(A > B) {
  22.         return 0;
  23.     }
  24.     return max(num_of_divisors_of_x(A, 1), k_deliv(A + 1, B));
  25. }
  26. // k_deliv(17, 23) = max(2, k_deliv(18, 23)) = max(2, 6) = 6
  27. // k_deliv(18, 23) = max(6, k_deliv(19, 23)) = max(6, 6) = 6
  28. // k_deliv(19, 23) = max(2, k_deliv(20, 23)) = max(2, 6) = 6
  29. // k_deliv(20, 23) = max(6, k_deliv(21, 23)) = max(6, 4) = 6
  30. // k_deliv(21, 23) = max(4, k_deliv(22, 23)) = max(4, 4) = 4
  31. // k_deliv(22, 23) = max(4, k_deliv(23, 23)) = max(4, 2) = 4
  32. // k_deliv(23, 23) = max(2, k_deliv(24, 23)) = max(2, 0) = 2
  33. // k_deliv(24, 23) = 0
  34. int sum(int A, int B, int K) {
  35.     if(A > B) {
  36.         return 0;
  37.     }
  38.     int div_A = num_of_divisors_of_x(A, 1);
  39.     int div_K = k_deliv(max(1, A - K), A - 1);
  40.     int suma = 0;
  41.     if(div_A > div_K) {
  42.         suma = A;
  43.     }
  44.     return sum(A + 1, B, K) + suma;
  45. }
  46. // div_A = 8
  47. // k_deliv(17, 23) = 6
  48. int main()
  49. {
  50.     int A, B, K;
  51.     cin >> A >> B >> K;
  52.     cout << sum(A, B, K) << endl;
  53.    
  54.    
  55.     // 24
  56.    
  57.    
  58.     return 0;
  59. }
  60.  
Advertisement
RAW Paste Data Copied
Advertisement