Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int broj_na_deliteli(int n, int idx) {
- if(idx > n) {
- return 0;
- }
- bool deliv = ((n % idx) == 0);
- return broj_na_deliteli(n, idx + 1) + deliv;
- }
- int k_deliv(int x, int idx, int k) {
- if(idx < x - k or idx == 0) {
- return 1;
- }
- if(broj_na_deliteli(idx, 1) >= broj_na_deliteli(x, 1)) {
- return 0;
- }
- return k_deliv(x, idx - 1, k);
- }
- int sum(int a, int b, int k) {
- if(a > b) {
- return 0;
- }
- int dodadi = 0;
- if(k_deliv(a, a - 1, k)) {
- dodadi = a;
- }
- return sum(a + 1, b, k) + dodadi;
- }
- int main() {
- int a, b, k;
- cin >> a >> b >> k;
- cout << sum(a, b, k) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement