Getting TLE for ATOM

Question : ATOM

This is my code for above question

#include<iostream>
#include<cstdio>

using namespace std;

long long int get_num()
{
 long long int num=0;
 char c=getchar_unlocked();
 while(!(c>='0' && c<='9'))
 c=getchar_unlocked();
 while(c>='0' && c<='9')
 {
  num=(num<<3)+(num<<1)+c-'0';
  c=getchar_unlocked();
 }
return num;
}

 int main()
 {
 long long int t=get_num();
 while(t--)
 {
  long long int n=get_num();
  long long int k=get_num();
  long long int m=get_num();
  int count=0;
  n*=k;
  while(n<=m)
  {
   count++;
   n*=k;
  }
  cout<<count<<endl;
  }
return 0;
}

Many other solutions with a similar code have got accepted with much less runtime. Explain what’s that causing for TLE in this solution.

The problem with the solution is that in the cases where the value of n*k exceeds the range of long long integer the value becomes negative. Hence the negative value still remains less than the value of m so the loop continues infinitely. Hence it needs to be checked whether the range of value is not exceeded.