My issue
I am getting correct output but when i submit, getting error message. Help me in solving this problem
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 r=sc.nextInt();
int s=sc.nextInt();
int diff=Math.abs(r-s);
int count=0;
for(int i=1;i<=Math.sqrt(diff);i++){
if(diff%i==0)
count++;
if(diff/i!=i)
count++;
}
System.out.println(count);
}
}
}
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 sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int r=sc.nextInt();
int s=sc.nextInt();
int diff=Math.abs(r-s);
int count=0;
for(int i=1;i<=Math.sqrt(diff);i++){
if(diff%i==0)
count++;
if(diff/i!=i)
count++;
}
System.out.println(count);
}
}
}
Learning course: Introduction to Number theory
Problem Link: Exam Cheating Practice Problem in Introduction to Number theory - CodeChef