Untitled
unknown
plain_text
7 months ago
1.0 kB
3
Indexable
Never
public static void main(String args[]) { seiveOfEratosthenesMod(90000, 99999); } public static void seiveOfEratosthenesMod(int l, int h){ int[] arr = new int[h-1]; for(int i = 0; i < h-1; i++) arr[i] = i+2; int n = (int)Math.sqrt(h); int in = 2; while(in <= n){ for(int k = 0; k < h-1; k++){ if(arr[k] != in && arr[k] % in == 0) arr[k] = -1; } in++; } int[] cond = new int[h-1]; int prev = -1; for(int k = 0; k < h-1; k++){ if(arr[k] != -1 && prev != -1 && (prev + arr[k] - 1) < h-1 && arr[prev + arr[k] - 1] != -1){ cond[prev + arr[k] - 1] = arr[prev + arr[k] - 1]; } if(arr[k] != -1) prev = arr[k]; } for(int la = l; la < h-1; la++){ if(cond[la] > 0) System.out.print(cond[la] + " "); } }
Leave a Comment