Recall that the fractional part function $\{x\}$ is defined as the unique real number $r$ with $0\le r<1$ such that $x-r$ is an integer. Recall also that the floor function $\lfloor x\rfloor$ is the unique integer $m$ such that $m\le x. Finally, recall that these two functions are related by the identity $x=\lfloor x\rfloor+\{x\}$.
If $a=0$, then your condition for $f(k)$ to be $1$ is $k=0n+b=b$, so we may write:
$f(k)=\left\lfloor\frac{1}{1+|k-b|}\right\rfloor=\frac{1}{1+|k-b|}-\left\{\frac{1}{1+|k-b|}\right\}.$
This works because for all $k$, $|k-b|\ge 0$, and $|k-b|=0$ exactly when $k=b$. Thus whenever $k\ne b$, $1+|k-b|>1$ and $0<\frac{1}{1+|k-b|}<1$, so $\left\lfloor\frac{1}{1+|k-b|}\right\rfloor=0$, and if $k=b$, then $1+|k-b|=1$ and $\frac{1}{1+|k-b|}=1$, so $\left\lfloor\frac{1}{1+|k-b|}\right\rfloor=1$.
Otherwise, the condiation for $f(k)$ to be $1$ is $k=an+b$, which is equivalent to $k-b=an$ or $\frac{k-b}{a}=n$. That is, $f(k)=1$ precisely when $\frac{k-b}{a}$ is an integer. Therefore we may write:
$f(k)=1-\left(\left\{\frac{k-b}{a}\right\}+\left\{-\frac{k-b}{a}\right\}\right).$
This works because for all $x$, if $\{x\}>0$, then $0\le 1-\{x\}<1$ and $-x-(1-\{x\})=-x+\{x\}-1=-(x-\{x\})-1=-\lfloor x\rfloor-1$, which is an integer, so we must have $\{-x\}=1-\{x\}$ and thus $\{x\}+\{-x\}=1$. On the other hand, if $\{x\}=0$, then $x$ is an integer, so $-x$ is also an integer and we must have $\{-x\}=0$, so $\{x\}+\{-x\}=0$. Therefore $\{x\}+\{-x\}$ is $0$ if $x$ is an integer and $1$ otherwise, so $1-\left(\{x\}+\{-x\}\right)$ is $1$ if $x$ is an integer and $0$ otherwise. We may then substitute $\frac{k-b}{a}$ for $x$ and get the desired function.