I am confused as to what data types has to do with the time complexity of a solution.
I came across a problem:
Problem link: CodeChef: Practical coding for everyone
Solution which got TLE:- #include <bits/stdc++.h>
using namespace std; #define int long long
int32_t main()
{
int a;int b;cin>>a>>b;
int temp=a;
int ans=0;
while(temp<=b)
{
ans++;
temp=temp*2;
}
cout<<ans;
return 0;
}
solution which got accepted:
#include <bits/stdc++.h>
using namespace std; #define int long long
@dhruv788 ,even after changing the data type to int ,it gives TLE.Only in case of double it is getting the solution accepted. Whats the logic behind this?
I have attached the problem link in the parent thread,test it out
It’s easy to see how to make a solution like e.g. this one TLE:
1111 2147483647
but I can’t see how you’d do it with e.g. this (note the - shudder - #define int long long), assuming of course that the constraints are correct (a fairly big assumption, as it’s a third-party contest and they didn’t manage to render them in LaTeX properly XD).
Edit:
Maybe someone should do a submission where they assert that 1 \le A \le B \le 10^{18}.