josiftepe

Untitled

Nov 28th, 2020
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. using namespace std;
  6. typedef long long ll;
  7. const int maxn = 1e5 + 10;
  8. const int INF = 2e9 + 10;
  9. int a, b, k;
  10. int number_of_divisors(int number, int i) {
  11.     if(i == number) {
  12.         return 1;
  13.     }
  14.     int cost = 0;
  15.     if(number % i == 0) {
  16.         cost = 1;
  17.     }
  18.     return number_of_divisors(number, i + 1) + cost;
  19. }
  20. bool is_k_divible(int number, int cnt_divs, int i) {
  21.     if(i == number) {
  22.         return true;
  23.     }
  24.     bool ret = true;
  25.     int cnt_i_divs = number_of_divisors(i, 1);
  26.     if(cnt_i_divs >= cnt_divs) {
  27.         return false;
  28.     }
  29.     ret &= is_k_divible(number, cnt_divs, i + 1);
  30.     return ret;
  31. }
  32. int rec(int i) {
  33.     if(i == b + 1) {
  34.         return 0;
  35.     }
  36.     int cost = 0;
  37.     if(is_k_divible(i, number_of_divisors(i, 1), max(i - k, 1))) {
  38.         cost = i;
  39.     }
  40.     return rec(i + 1) + cost;
  41. }
  42. int main()
  43. {
  44.     ios_base::sync_with_stdio(false);
  45.     cin >> a >> b >> k;
  46.     cout << rec(a) << endl;
  47.     return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment