Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <cmath>
- #include <math.h>
- #include <vector>
- #include <queue>
- using namespace std;
- int num_of_divisors_of_x(int x, int i) {
- if(i > x) {
- return 0;
- }
- int divisor = 0;
- if(x % i == 0) {
- divisor = 1;
- }
- return num_of_divisors_of_x(x, i + 1) + divisor;
- }
- int k_deliv(int A, int B) {
- if(A > B) {
- return 0;
- }
- return max(num_of_divisors_of_x(A, 1), k_deliv(A + 1, B));
- }
- // k_deliv(17, 23) = max(2, k_deliv(18, 23)) = max(2, 6) = 6
- // k_deliv(18, 23) = max(6, k_deliv(19, 23)) = max(6, 6) = 6
- // k_deliv(19, 23) = max(2, k_deliv(20, 23)) = max(2, 6) = 6
- // k_deliv(20, 23) = max(6, k_deliv(21, 23)) = max(6, 4) = 6
- // k_deliv(21, 23) = max(4, k_deliv(22, 23)) = max(4, 4) = 4
- // k_deliv(22, 23) = max(4, k_deliv(23, 23)) = max(4, 2) = 4
- // k_deliv(23, 23) = max(2, k_deliv(24, 23)) = max(2, 0) = 2
- // k_deliv(24, 23) = 0
- int sum(int A, int B, int K) {
- if(A > B) {
- return 0;
- }
- int div_A = num_of_divisors_of_x(A, 1);
- int div_K = k_deliv(max(1, A - K), A - 1);
- int suma = 0;
- if(div_A > div_K) {
- suma = A;
- }
- return sum(A + 1, B, K) + suma;
- }
- // div_A = 8
- // k_deliv(17, 23) = 6
- int main()
- {
- int A, B, K;
- cin >> A >> B >> K;
- cout << sum(A, B, K) << endl;
- // 24
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement