TLE DUE TO LARGE INPUT CASE IN A PROBLEM

In a question the Constraints give is [1≤X≤10^18 ] and the time limit give is 1sec , so for this i have used unsigned long long int data type and scanf and printf in my cpp code but still i am getting tle for the code , can anyone please explain me how to take inputs or optimize the code for 10^18 inputs.

Please share the problem link.

actually this things had happened with me for more than one time for different questions which generally have large input constraints so can you please give a general explanation for this .

I know this might be mind blowing, but have you ever considered that maybe the input isn’t giving TLE but other sections of your code instead?

2 Likes

You need to optimize your algorithm.
You cannot use brute force as the problems are designed to pass only optimal solutions.
If you don’t mention the problem links we can’t help you

Try to solve those questions in atmost O(logN) time.
Because for N=10^18, O(N) can give TLE.

1 Like