Help me in solving SEVENRINGS problem

My issue

I am getting time limit exceed

My code

``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner scan=new Scanner(System.in);
int t=scan.nextInt();
for(int i=0;i<t;i++)
{
int n=scan.nextInt();
int x=scan.nextInt();
int y=n*x;
int count=0;
while(y>0)
{
n=n/10;
count++;
}
if(count==5 && y/10000!=0 )
{
System.out.println("YES");
}
else
{
System.out.println("NO");
}

}
}
}

``````

Problem Link: SEVENRINGS Problem - CodeChef

You could simply have checked if the number is bigger than biggest 4 digit number (9 999) and smaller than smallest 6 digit number (100 000).

Here is my code (in Python) for reference

``````# cook your dish here
for _ in range(int(input())):
n,x=map(int,input().split())
n=n*x
if((n>9999)and(n<100000)):
print('yes')
else:
print('no')
``````

you can use this code

include
using namespace std;

int main() {
int t;
cin>>t;
while(t–){
int n,x;
cin>>n>>x;
int d =n*x;
if(d>=10000 && d<=99999 ){
cout<<“YES”<<endl;
}else
{
cout<<“NO”<<endl;
}
}

``````return 0;
``````

}