Getting TLE in FLOORI4 , September Challenge 2014.

Guys my code for FLOORI4 ,September 2014 (CodeChef: Practical coding for everyone) is giving TLE.
Please me why is it exceeding the time limit and how should i improvise upon my code.
Link to code : qWtRPV - Online C Compiler & Debugging Tool - Ideone.com

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.