Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  ds
Language: JAVA
Code:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class SimpleNum {
    public static ArrayList<Integer> sieve(int n){
        ArrayList<Integer> result = new ArrayList<Integer>();
        boolean[] nums = new boolean[n+1];
        Arrays.fill(nums, true);
        int i = 2;
        while(i*i<=n){
            if(nums[i]==true){
                int j = i*i;
                while(j<=n){
                    nums[j] = false;
                    j += i;
                }
            }
            i++;
        }
        for(int l=1; l<=n; l++){
            if(nums[l]==true){
                result.add(l);
            }
        }
        return result;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        System.out.println(sieve(15485863).get(scan.nextInt()));
    }
}
Comments: