Solve the functional equation $f(xy) = f(x)f(y) - f(x + y) + 1$ and $f(1) = 2$
Solution 1:
The condition $f(1)=2$ is unnecessary. The only functions $f:\mathbb{Q}\to\mathbb{C}$ sastisfying $$f(xy)=f(x)\,f(y)-f(x+y)+1\tag{$\star$}$$ are the constant function $f\equiv 1$ and the function $f(x)=x+1$ for all $x\in\mathbb{Q}$.
First, as ajotaxe observed, $f(0)=1$. If $f(1)=1$, then we obtain from $(\star)$ that $$f(x)=f(x\cdot 1)=f(x)\,f(1)-f(x+1)+1=f(x)-f(x+1)+1$$ for all $x\in\mathbb{Q}$. This means $f(x+1)=1$ for all $x\in\mathbb{Q}$, which leads to $f\equiv 1$. From now on, we assume that $f(1)\neq 1$.
By plugging in $x:=1$ and $y:=-1$ into $(\star)$, we have $$f(-1)=f(1)\,f(-1)\,.$$ Because $f(1)\neq 1$, we must have $f(-1)=0$. Putting $y:=-1$ yields $$f(-x)=-f(x-1)+1\,.\tag{*}$$ Now, plugging in $x:=1$ and $y:=-2$ into $(\star)$, we obtain $$f(-2)=f(1)\,f(-2)-f(-1)+1=f(1)\,f(-2)+1\,.$$ Using $(*)$, we have $f(-2)=-f(1)+1$, so the equation above translates to $$-f(1)+1=-\big(f(1)\big)^2+f(1)+1\,.$$ This gives $$\big(f(1)\big)^2-2\,f(1)=0\,.$$ That is, $f(1)=0$ or $f(1)=2$.
If $f(1)=0$, then $y:=1$ into $(\star)$ leads to $$f(x)=-f(x+1)+1\,.\tag{$\Box$}$$ This proves that $f(n)=\frac{1+(-1)^n}{2}$ for every integer $n$, and from $(\Box)$, we get $$f(x+2)=f(x)$$ for all $x\in\mathbb{Q}$. Now, if we plug in $y:=n$ into $(\star)$, where $n$ is an even integer, then $$f(xn)=f(x)\,f(n)-f(x+n)+1=f(x)-f(x)+1=1$$ for every $x\in\mathbb{Q}$. Thus, substituting $x:=\frac{1}{2}$ and $n:=2$ in the previous equation, we obtain $$0=f(1)=f\left(\frac{1}{2}\cdot 2\right)=1\,,$$ which is absurd. Hence, $f(1)\neq 0$, and so $f(1)=2$ as required.
Now, $(\star)$ with $y:=1$ implies that $$f(x+1)=f(x)+1$$ for all $x\in\mathbb{Q}$. Ergo, we can see that $f(n)=n+1$ for every integer $n$. Consequently, for a rational number $x=\frac{p}{q}$, where $p,q\in\mathbb{Z}$ with $q>0$, we have $$p+1=f(p)=f\left(\frac{p}{q}\cdot q\right)=f\left(\frac{p}{q}\right)\,f(q)-f\left(\frac{p}{q}+q\right)+1=(q+1)\,f\left(\frac{p}{q}\right)-f\left(\frac{p}{q}\right)-q+1\,.$$ Hence, $$f(x)=f\left(\frac{p}{q}\right)=\frac{p+q}{q}=\frac{p}{q}+1=x+1\,,$$ as desired.
P.S.: It is a very interesting question what happens if the domain extends to $\mathbb{R}$. All I know is that, if a nonconstant function $f:\mathbb{R}\to\mathbb{Q}$ satisfies $(\star)$, then $$f(x+r)=f(x)+r$$ and $$f(rx)=r\,f(x)-r+1$$ for all $x\in\mathbb{R}$ and $r\in\mathbb{Q}$.
Solution 2:
For $x=y=0$, $$f(0)=f(0)^2-f(0)+1$$ Then $f(0)=1$.
With the equation $f(n+1)=f(n)+1$, you have it (see Thomas Andrews' comment).