All numbers $Z$, $n$ and the $\mathrm{Threshold}$ are natural numbers.
My inputs are $Z$ and $n$, and I would like to find a minimal $x$ such that
$$\operatorname{LCM}(Z - x, 2^n) \le \mathrm{Threshold}$$
where threshold is an arbitrary constant I can choose and should be in the ballpark of 5000-12000 or therebouts.
$x$ is a natural number, too, including $0$.
For example: $Z=2011, n=5$. Then $x=11$ or $x=3$ as:
> data.frame(candidate = 2000:2011) %>% mutate(lcm = sapply(candidate, function (x) LCM(x, 2**5))) %>% arrange(lcm)
candidate lcm
1 2000 4000
2 2008 8032
3 2004 16032
4 2002 32032
5 2006 32096
6 2010 32160
7 2001 64032
8 2003 64096
9 2005 64160
10 2007 64224
11 2009 64288
12 2011 64352
depending on the choice of $\mathrm{Threshold}$.
My problem is that I don't really know where to start to tackle this. I also don't know if this is solvable directly, or if I need to do it by means of a program.
If I need to do it by a program, I would need to optimize for the number of candidates to calculate the LCM for.
Any pointers greatly appreciated. :)