Getting TLE in FLOORI4 , September Challenge 2014.

Guys my code for FLOORI4 ,September 2014 (http://www.codechef.com/SEPT14/problems/FLOORI4) is giving TLE.
Please me why is it exceeding the time limit and how should i improvise upon my code.
Link to code : http://ideone.com/qWtRPV

Your time complexity is O(n).This will exceed time limit as n can be as high as 1010.Try to bring it to O(sqrt(n)),then it’ll pass.