Last active
July 17, 2016 13:29
-
-
Save Jack-Saleem/b92e8ab4158065728bdd20a44de26740 to your computer and use it in GitHub Desktop.
Codeforces 26A AlmostPrime program in java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.ArrayList; | |
import java.util.Scanner; | |
public class PrimeNumbers | |
{ | |
public static void main(String[] args) | |
{ | |
Scanner z=new Scanner(System.in); | |
int n=z.nextInt(); | |
ArrayList al=new ArrayList(); | |
for(int i=2;i<=3000;i++){ | |
boolean flag=true; | |
for(int j=2;j<=Math.sqrt(i);j++){ | |
if(i%j==0) | |
flag=false; | |
} | |
if(flag) | |
al.add(Integer.valueOf(i)); | |
} | |
int ans=0; | |
for(int i=0;i<=n;i++){ | |
int k=0; | |
for(int j=0;j<al.size();j++){ | |
if(i%Integer.parseInt(al.get(j).toString())==0) | |
k++; | |
} | |
if(k==2) | |
ans++; | |
} | |
System.out.println(ans); | |
z.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment