Facing issue in taking mod

https://ideone.com/YX4Uyj ---->solution link
https://www.codechef.com/COOK101B/problems/YVNUM ---->question link

Not able to understand where to take mod in the code.Code is running fine for smaller inputs

See, long long data type can store number with max of 18 digits. And |N| = 10^5, so this logic will surely not work.
HINT:

  1. Take input of N as a string.
  2. Try finding mod of N.
  3. ans = 123 * 10^6 + 231 * 10^3 + 312 * 10^0. I broke the problem to this. 10^x part can be calculated using modular exponentiation, and you know the mod of 123 from step 2.
  4. mod(123)=123(lets say x).
    multiply it by 10-> 1230.
    add 1 to it (first digit) -> 1231.
    Subtract 1000 from it (first digit * 10^3) -> 231.
  5. If these serious of operations are applied on answer of step 2, we can next circular left shifted string.

Hope this helps. It is too confusing. Do let me know in case of any doubts.

https://ide.codingblocks.com/s/46940

Here is my submission for your reference. It is too confusing, so try yourself and let me know in case of any doubts.