Java Saved Program: placid-city



Here's the online compiler accompanied with IDE at your service. This is a saved code by one of our users. Try it out or save your own from the IDE page and don't forget to leave a feedback. You can find that at the bottom of the page.


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

/* Name of the class has to be "Script" only */
class Script
{
    public static void main (String[] args)
    {
         int n,i,j,count=0,sum=0;
         Scanner sc = new Scanner(System.in);
         n=sc.nextInt();
	   int[] a=new int[n];
	   for(i=0;i<n;i++)
	   {
		   a[i]=sc.nextInt();
	   }
	   for(i=1;i<n;i++)
	   {
		   for(j=1;j<=i;j++)
		   {
			   if(i%j==0)
			   {
				   count++;
			   }
		   }
		  
			   if(count==2)
			   {
				   sum=sum+(a[i]);
			   }
			   count=0;
		   
	    }
	   System.out.println(sum);

   } 
}
Execute