Show that $f:X\to \mathbb{RP}^n$ factors through $S^n\to\mathbb{RP}^n$ iff $f^*:H^1(\mathbb{RP}^n,Z_2)\to H^1(X,Z_2)$ is zero Problem
Show that
(1) $f:X\to \mathbb{RP}^n$ factors through $S^n\to\mathbb{RP}^n$ iff $f^*:H^1(\mathbb{RP}^n,Z_2)\to H^1(X,Z_2)$ is zero
(2) $f:X\to \mathbb{CP}^n$ factors through $S^{2n+1}\to\mathbb{CP}^n$ iff $f^*:H^2(\mathbb{CP}^n,Z)\to H^2(X,Z)$ is zero
It's a concise question. I think the solution should not be so hard. But, I fail to solve it, rigorouly and systematically.
I have a few idea for (1): first of all, the "only if" part is easy since $H^1(S^n,Z_2)$ is trivial when $n>1$. (I guess we should assume $n>1$). 
Conversely, I try to use the condition "$f^*:H^1(\mathbb{RP}^n,Z_2)\to H^1(X,Z_2)$ is zero" to show $f_*:\pi_1(X) \to \pi_1(\mathbb{RP}^n)$ is also zero, from which we can lift $f$ to $S^n$ and this is the desired factor.But,I am not sure this strategy would works.
What's more, how to show (2)? Is it similar to (1)?
Please help!
 A: $\newcommand{\RP}{\mathbb{RP}} \newcommand{\Z}{\mathbb{Z}}$
I will assume that $X$ is path-connected, because we can solve the lifting problem separately on each path component, and a map to $H^*(X;R)$ is zero iff it's zero when co-restricted to each path component.

(1) The map $S^n \to \RP^n$ is a universal covering, so for a lift of $f : X \to \RP^n$ to exist, it is necessary and sufficient for $f_* : \pi_1(X) \to \pi_1(\RP^n)$ to be trivial. It's known that $\pi_1(\RP^n) = \Z/2\Z$ (with a generator $\gamma_n$), so the Hurewicz theorem and universal coefficient theorem give that $H^1(\RP^n; \Z/2\Z) = \hom(\pi_1(\RP^n), \Z/2Z) \cong \Z/2\Z$.
Let $[\alpha] \in \pi_1(X)$. We want to show that $f_*[\alpha] = e$. Since $\pi_1(\RP^n)$ is generated by $[\gamma_n]$, we have that $f_*[\alpha] = [\gamma_n]^k$ for some $k \in \Z/2\Z$; we want to show that $k = 0$. Let $u \in H^1(\RP^n; \Z/2\Z) \cong \Z/2\Z$ be the generating class, then by definition $u(h([\gamma_n]^k)) = u(k \cdot [\gamma_n]) = k$, where $h : \pi_1(\RP^n) \to H_1(\RP^n)$ is the Hurewicz isomorphism (first $\gamma_n$ is seen as a loop, then as a cycle). But $f^*(u) = 0$, so $u(f_*[\alpha]) = (f^*(u))([\alpha]) = 0$, and finally $k = 0$.

(2) This is more complicated, as both $\newcommand{\CP}{\mathbb{CP}}\CP^n$ and $S^{2n+1}$ are simply connected; covering space theory is useless here. But the projection $S^{2n+1} \to \CP^n$ is a fibration, with fiber $S^1$. The existence of a factorization is equivalent to the existence of a section $X \to Y$, where $Y$ is defined as the pullback:
$$\require{AMScd}
\begin{CD}
Y = X \times_{\CP^n} S^{2n+1} @>>> S^{2n+1} \\
@VVV @VVV \\
X @>{f}>> \CP^n
\end{CD}$$
The map $Y \to X$ is again a fibration, with fiber $S^1$. Obstruction theory provides obstructions to the existence of such a section. They are cohomology classes $\omega_k \in H^{k+1}(X; \pi_k(S^1))$, and they need to all be zero for the lift to exist (in reality, obstructions are defined one after the other: first $\omega_0$, then if $\omega_0 = 0$ you can define $\omega_1$, and so on; at the first nonzero obstruction, you stop, otherwise a lift exists).
Since only the $\pi_1$ of the circle is nontrivial, the only possible obstruction is $\omega_1 \in H^2(X; \Z)$. Going through the steps of the proof of obstruction theorems, one sees that $\omega_1$ is the image of the generator $x \in H^1(BS^1; \Z)$, where $BS^1$ is the classifying space of the topological group $S^1$. This classifying space is known: it's $BS^1 = \CP^\infty$. It's also known that for all $n$, the generator $x_n \in H^1(\CP^n; \Z)$ is the image of $x$ through the inclusion $i_n : \CP^n \hookrightarrow \CP^\infty$. Since by hypothesis $x_n \mapsto 0 \in H^2(X; \Z)$, it follows that $\omega_1 = (i \circ f)^*(x) = f^*(x_n) = 0$, and thus the lift exists.
