i got the mistake. cout<<y<<endl; instead of cout<<a<<endl;. BTW i have not considered n=0 as per constrained.
Thanks a lot.
after reading the comment of @pk301 i realized that it is O(no of digits) i didn’t do a proper analysis sorry saw you solution it is actually O(1) well done
well done @eugalt if any one didn’t get % 9 part the can look the comment of @sideralis nice explanation both of you @eugalt your code is very well represented.
O(no of digits) is O(log N).
Why my code is giving WA. I solved using digital root
https://www.codechef.com/viewsolution/36157204