The question states that the number of students with at least $\displaystyle k$ questions wrong is $\displaystyle 4^{n-k}$. Hence the number that actually get exactly $\displaystyle k$ wrong, $\displaystyle N_k$ , must be the number that get at least $\displaystyle k$ wrong minus those that get at least $\displaystyle (k+1)$ wrong. So we have

$\displaystyle N_k = 4^{n-k} - 4^{n-k-1}$ .

So if we let $\displaystyle N_q$ be the total number of wrongly answered questions then

$\displaystyle N_q = n + \sum_{k=1}^{n-1} k N_k $,

$\displaystyle = n + \sum_{k=1}^{n-1} k (4^{n-k} - 4^{n-k-1})$,

$\displaystyle = n + \sum_{k=1}^{n-1} k 4^{n-k} - \sum_{k=1}^{n-1} k 4^{n-k-1}$,

$\displaystyle = n + \sum_{k=1}^{n-1} k 4^{n-k} - \sum_{k=1}^{n-1} (k+1) 4^{n-(k+1)} +

\sum_{k=1}^{n-1} 4^{n-(k+1)}$,

$\displaystyle = n + \sum_{k=1}^{n-1} k 4^{n-k} - \sum_{m=2}^{n} m 4^{n-m} + \sum_{k=1}^{n-1} 4^{n-(k+1)} $ (letting $\displaystyle m= k+1$),

$\displaystyle = n + \sum_{k=1}^{n-1} k 4^{n-k} - \sum_{m=2}^{n} m 4^{n-m} + \sum_{k=1}^{n-1} 4^{n-(k+1)} $,

$\displaystyle = n + 4^{n-1} - n + \sum_{k=1}^{n-1} 4^{n-(k+1)} $,

$\displaystyle = \sum_{k=0}^{n-1} 4^{n-(k+1)} $,

$\displaystyle = \sum_{p=0}^{n-1} 4^{p} $ (letting $\displaystyle p = n-(k+1)$),

$\displaystyle = \frac{4^{n}-1}{4-1} = \frac{1}{3}(4^n -1)$.

(I know I could have explicitly written out the sum, 'spot the pattern' - as I did on paper, but decided this was typographically easier than using an array).

So we have that

$\displaystyle 341 = \frac{1}{3}(4^n -1)$

and solving gives us that

$\displaystyle \color[rgb]{0,0,1} \boxed{n = 5}$.