Untitled

mail@pastecode.io avatar
unknown
markdown
7 months ago
332 B
0
Indexable
Never

bool canBeComposed(int n, int x) { // Base cases if (n == 0) return true; if (n < 0) return false;

// Try to break `n` using `x`
bool usingX = canBeComposed(n - x, x);

// Try to break `n` using `x-1`
bool usingXMinusOne = canBeComposed(n - x + 1, x);

return usingX || usingXMinusOne;

}