Greetings.
I see. I often see my lecturers using shortforms like "hth" & etc. without knowing what it means.
Your suggestion to the second problem was cool.
How about converting the number to String and then using the string length function?
About the first problem. May I rephrase what you were trying to mean.
Let's say if I input n=1, must I get 2^2 = 4 as the result?
Similarly, if I input n=2, the result must be 2^2 + 4^2 = 20.
Is this what you want?