Last active
October 25, 2015 10:32
-
-
Save kodyzrodlowe/73f9da538dab929045bb to your computer and use it in GitHub Desktop.
This file contains 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
package liczbydoskonale; | |
import java.util.Arrays; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
class Zero implements Runnable { | |
public ExecutorService exec = Executors.newCachedThreadPool(); | |
Zero(int pos, int n, int array[]) { | |
this.pos = pos; | |
this.n = n; | |
this.array = array; | |
} | |
public int pos = 2; | |
public int n = 0; | |
public int[] array; | |
public void run() { | |
int i = pos; | |
int k = 1; | |
while (i < n) { | |
pos *= k; | |
array[pos] = this.pos; | |
i++; | |
} | |
} | |
} | |
class PerfectNumber { | |
public PerfectNumber(int n) { | |
this.n = n; | |
} | |
private int n = 0; | |
private int array[]; | |
public void count() { | |
array = new int[n]; | |
Arrays.fill(array, 0); | |
for ( int i = 0; i < n; i++ ){ | |
if (array[i] == 0) { | |
new Thread(new Zero(i, n, array)).start(); | |
} | |
} | |
} | |
} | |
public class Main { | |
public static void main(String[] args) { | |
new PerfectNumber(30); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment