Error in boring factorial while submitting in spoj

https://ide.codingblocks.com/s/110914 , this is code with fast modulo expo using recursion giving me wrong ans , and when same code i have applied with fast modulo with bitmask , it giving me correct ans on spoj
https://ide.codingblocks.com/s/110916

   return (((r%mod)*(x%mod)*(r%mod)))%mod;

iss statement ko do alag statements me multiply karo, it will give write because 1e91e91e9 > 1e18

now it is giving tle :- https://ide.codingblocks.com/s/111069 , problem link :- https://www.spoj.com/problems/DCEPC11B/

any help please !!!

use simply modular exponentiation using bitmsking, sont try recusion if its not working

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.