JAN COOK OFF -EXMCHT

My code matches several of the accepted solution still it was giving wrong answer

/* 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 sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0)
{
int a=sc.nextInt();
int b=sc.nextInt();
a–;
b–;
int m=0,c=0;
if(a>b)
m=a-b;
else
m=b-a;
int i=0;
for(i=1;i
i<=m;i++)
if(m%i==0)
c++;
if(m/i!=i)
c++;

	     System.out.println(c); 
	     t--;
	 }
}

}

Use long instead of int

dude you are going till O(n) go till square root
I can’t see because the code is not formatted so please format that as well :slight_smile:

1 Like

Hey,thank you for replying.
I did use the square root method,I guess my solution was flagged wrong due to the constraint A=B
Here’s the submission link
https://www.codechef.com/viewsolution/29080597

1 Like

no need to do a-- and b–.