Let $a_1,\cdots, a_n$ be integers such that $a_i\geq 2$ for all $i$ and $k>0$ another integer.
I am interested in whether there exist integers $x_1,\cdots, x_n$ with $0<x_i<a_i$ satisfying:
$$ \frac{x_1}{a_1}+ \cdots + \frac{x_n}{a_n}=k \ \ (*)$$
For example, if $n=2,k=1$, there exist a solution in the specified range iff $\text{gcd}(a_1,a_2) \neq 1$, in other words $\text{lcm}(a_1,a_2)-a_1a_2 \neq 0$.
Question: For what pairs $n,k$ is there a polynomial $F$ whose inputs are $\text{lcm}$ of various subsets of $\{a_i\}_{1\leq i\leq n}$ such that (*) has a solution in the specified range if and only if $F\neq 0$ (see some examples I have in mind below)?
Some observations: If $k\geq n$ then $F\equiv 0$ works, trivially.
Some calculations for small values of $(n,k)$ suggest the following strange function: for each subset $I \subset \{1,\cdots,n\}$ define $$f_I(a_1,\cdots,a_n):= \frac{\prod_{i\in I}a_i}{\text{lcm}\{a_i\}_{i\in I}}$$
For $I=\varnothing$ we set $f_I=1$. Let:
$$F(a_1,\cdots,a_n):= \sum_{I\subset \{1,\cdots,n\}}(-1)^{|I|}f_I(a_1,\cdots,a_n) $$
(You can replace $F$ by a polynomial of the $\text{lcm}$s which vanishes at the same time). This works for $(n,k)=(2,1)$ and probably $(3,1)$ (which would imply $(3,2)$). It does not work for $(4,1)$ but seems to work for some sequence with $(n,k)= (4,2)$ (may be the function depends on $n/k$?). Have anyone seen this kind of formula before in other contexts?
PS: I am not sure what tags should be used. Please feel free to re-tag.
EDIT: Apparently this question is related to existence of lattice points on a polytope. I checked through some of the references pointed to in this question on MO, but could not find the exact answer to what I wanted.