SPOJ String Powers

Getting TLE

Please Help

http://ideone.com/ybphVN