44 lines
1.5 KiB
Java
44 lines
1.5 KiB
Java
import java.util.Arrays;
|
|
import java.util.HashSet;
|
|
import java.util.Set;
|
|
import java.util.stream.IntStream;
|
|
|
|
public class Ring {
|
|
private int n;
|
|
|
|
Ring(int n) {
|
|
this.n = n;
|
|
}
|
|
|
|
public String findRingDetails() {
|
|
int[] reversibleElements = getReversibleElements();
|
|
int[] zeroDivisors = getZeroDivisors();
|
|
Set nilpotentElements = getNilpotentElements(zeroDivisors);
|
|
int[] idempotentElements = getIdempotentElements();
|
|
return "[" + Arrays.toString(reversibleElements) + ", " + Arrays.toString(zeroDivisors) + ", " + nilpotentElements + ", " + Arrays.toString(idempotentElements) + "]";
|
|
}
|
|
|
|
private int[] getReversibleElements() {
|
|
return IntStream.rangeClosed(0, n - 1).filter(k -> NWDCalculator.findNWD(k, n) == 1).toArray();
|
|
}
|
|
|
|
private int[] getZeroDivisors() {
|
|
return IntStream.rangeClosed(0, n - 1).filter(k -> NWDCalculator.findNWD(k, n) > 1).toArray();
|
|
}
|
|
|
|
private Set getNilpotentElements(int[] zeroDivisors) {
|
|
Set<Integer> nilpotentElements = new HashSet<>();
|
|
for (int i = 0; i < n; i++) {
|
|
for (int i1 : zeroDivisors) {
|
|
if (Math.pow(i1, i) % n == 0)
|
|
nilpotentElements.add(i1);
|
|
}
|
|
}
|
|
return nilpotentElements;
|
|
}
|
|
|
|
private int[] getIdempotentElements() {
|
|
return IntStream.rangeClosed(0, n - 1).filter(k -> k * k % n == k).toArray();
|
|
}
|
|
}
|