Quote:How do I solve this narcistic formula
The problem with your code is that it do not try to solve the problem, it is just wrong.
Read carefully the requirement again.
Try to solve each example by hand as a mean to get familiar with the algorithm.
you will need to split the number in its digits. Getting the unit digit is done by getting the reminder of an integer division by 10.