Exception in thread “main” java.util.NoSuchElementException
at java.util.Scanner.throwFor(Scanner.java:862)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextInt(Scanner.java:2117)
at java.util.Scanner.nextInt(Scanner.java:2076)
at Main.main(Main.java:14)
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
int t;
// java.io.BufferedReader t = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
Scanner sc = new Scanner(System.in );
t = sc.nextInt();
for (int i=0;i<t;i++ )
{
int n;
// java.io.BufferedReader n = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
n = sc.nextInt();
int a[] =new int[n];
for ( i=0;i<n;i++)
{
// java.io.BufferedReader a[i] = new java.io.BufferedReader (new java.io.InputStreamReader (System.in));
a[i] = sc.nextInt();
}
int count[]= new int[n];
for (i=0;i<n;i++)
count[i]=0;
for (i=0;i<n;i++)
{ for (int j=n-1;j>i;j–)
{
if (a[i]%a[j]==0)
count[j]++;
}
}
int max = count[0];
for (i = 1; i <n; i++)
if (count[i] > max)
max = count[i];
System.out.println(max);
}
}
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)
{
int t;
Scanner sc = new Scanner(System.in);
t = sc.nextInt();
for (int i=0;i<t;i++ )
{
int n;
n = sc.nextInt();
int a[] =new int[n];
for ( i=0;i<n;i++)
{
a[i] = sc.nextInt();
}
int count[]= new int[n];
for (i=0;i<n;i++)
count[i]=0;
for (i=0;i<n;i++)
{ for (int j=n-1;j>i;j--)
{
if (a[i]%a[j]==0)
count[j]++;
}
}
int max = count[0];
for (i = 1; i <n; i++)
if (count[i] > max)
max = count[i];
System.out.println(max);
}
}
}