Skip to content

Instantly share code, notes, and snippets.

@kodyzrodlowe
Last active October 25, 2015 10:32
Show Gist options
  • Save kodyzrodlowe/73f9da538dab929045bb to your computer and use it in GitHub Desktop.
Save kodyzrodlowe/73f9da538dab929045bb to your computer and use it in GitHub Desktop.
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