Questionuglynumbers

why im getting wrong

your logic is absolutely correct but there is integer overflow for large values of n, so you should either use long int or unsigned int, then you will get WA.

Feel free to ask here furthur doubt if you have in this question.