New course! Every coder should learn Generative AI!
Try a free lesson0
how large is your number?
if it is a 10 digit number, it can be looped 10 times and the square of each digit is added to variable.
I can't think of a better solution in terms of time complexity.