harvish harvish - 3 months ago 9
Java Question

Error: main class not found

When compiling the program I get the error as

Could not find the main class: Solution. Program will exit.

The program is:

import java.util.*;

public class Solution{
public static long[] factors(long a){
long[] b;
b=new long[50];
int count=0;
for(long i=1L;i<=a/2;i++)
if(a%i==0) b[count++]=i;
return b;

public static void main(String[] args) {

Scanner in=new Scanner(System.in);

int N=in.nextInt();
long K=in.nextInt();
long[] fact=factors(K);
for(int i=0;i<N;i++)
long num=in.nextInt();
for(int j=0;j<fact.length;j++)
if(num%fact[j]==0 && fact[j]!=1) {fact[j]=1;continue l1;}

int result=0;
for(int i=0;i<fact.length;i++)
if(fact[i]!=1) ++result;


This will not compile because the main method is not belong to a class. Put the main method inside the class to solve the problem. And your code is throwing arithmetic exception divide by zero should be fixed like that.

for(int j=0;j<fact.length;j++)
  if (fact[j] != 0)
    if(num%fact[j]==0 && fact[j]!=1) {
      fact[j]=1;continue l1;