Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
b0dff74e04 | ||
6ec94b66e5 |
47
exersize1dommro1/EclideamAlgorithm.java
Normal file
47
exersize1dommro1/EclideamAlgorithm.java
Normal file
@ -0,0 +1,47 @@
|
||||
public class EclideamAlgorithm {
|
||||
|
||||
private int nwd;
|
||||
private int combinationOfA;
|
||||
private int combinationOfB;
|
||||
|
||||
public EclideamAlgorithm(int numberA, int numberB) {
|
||||
int[][] matrix = new int[2][3];
|
||||
matrix[0][0] = 1;
|
||||
matrix[1][1] = 1;
|
||||
matrix[0][2] = numberA;
|
||||
matrix[1][2] = numberB;
|
||||
|
||||
while (matrix[0][2] != 0 && matrix[1][2] != 0) {
|
||||
if (matrix[0][2] > matrix[1][2]) {
|
||||
matrix[0][0] = matrix[0][0] - matrix[1][0];
|
||||
matrix[0][1] = matrix[0][1] - matrix[1][1];
|
||||
matrix[0][2] = matrix[0][2] - matrix[1][2];
|
||||
} else {
|
||||
matrix[1][0] = matrix[1][0] - matrix[0][0];
|
||||
matrix[1][1] = matrix[1][1] - matrix[0][1];
|
||||
matrix[1][2] = matrix[1][2] - matrix[0][2];
|
||||
}
|
||||
}
|
||||
|
||||
if (matrix[0][2] != 0) {
|
||||
nwd = matrix[0][2];
|
||||
combinationOfA = matrix[0][0];
|
||||
combinationOfB = matrix[0][1];
|
||||
} else {
|
||||
nwd = matrix[1][2];
|
||||
combinationOfA = matrix[1][0];
|
||||
combinationOfB = matrix[1][1];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int getGCD() {
|
||||
return nwd;
|
||||
}
|
||||
public int getCombinationOfA() {
|
||||
return combinationOfA;
|
||||
}
|
||||
public int getCombinationOfB() {
|
||||
return combinationOfB;
|
||||
}
|
||||
}
|
90
exersize1dommro1/Homework.java
Normal file
90
exersize1dommro1/Homework.java
Normal file
@ -0,0 +1,90 @@
|
||||
import java.util.Scanner;
|
||||
import java.util.Vector;
|
||||
|
||||
public class Homework {
|
||||
|
||||
private int input;
|
||||
private Vector<String> output;
|
||||
private Vector<Integer> zeroDevisors;
|
||||
private Vector<Integer> units;
|
||||
private Vector<Integer> nilpotents;
|
||||
private Vector<Integer> idempotents;
|
||||
|
||||
Homework(int input) {
|
||||
this.input = input;
|
||||
output = new Vector<>();
|
||||
zeroDevisors = new Vector<>();
|
||||
units = new Vector<>();
|
||||
nilpotents = new Vector<>();
|
||||
idempotents = new Vector<>();
|
||||
calculateHomework();
|
||||
}
|
||||
|
||||
public String getOutput() {
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private void calculateHomework() {
|
||||
calculateUnits();
|
||||
calculateZeroDevisors();
|
||||
calculateNilpotents();
|
||||
calculateIdempotents();
|
||||
|
||||
output.add(units.toString());
|
||||
output.add(zeroDevisors.toString());
|
||||
output.add(nilpotents.toString());
|
||||
output.add(idempotents.toString());
|
||||
}
|
||||
|
||||
private void calculateUnits() {
|
||||
for (int element = 1; element < input; element++) {
|
||||
EclideamAlgorithm eclideamAlgorithm = new EclideamAlgorithm(element,input);
|
||||
if ( eclideamAlgorithm.getGCD() == 1) {
|
||||
units.add(element);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void calculateZeroDevisors() {
|
||||
zeroDevisors.add(0);
|
||||
for (int element = 1; element < input; element++) {
|
||||
for (int numberB = 1; numberB < input; numberB++) {
|
||||
if ((element * numberB) % input == 0) {
|
||||
zeroDevisors.add(element);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateNilpotents() {
|
||||
nilpotents.add(0);
|
||||
for (int number = 1; number < input; number++) {
|
||||
int temporary = number;
|
||||
for (int power = 2; power < input; power++) {
|
||||
temporary = temporary * number;
|
||||
if ((temporary) % input == 0) {
|
||||
nilpotents.add(number);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateIdempotents() {
|
||||
idempotents.add(0);
|
||||
for (int number = 1; number < input; number++) {
|
||||
if ((number * number) % input == number) {
|
||||
idempotents.add(number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] arg) {
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
int input = scanner.nextInt();
|
||||
Homework homework = new Homework(input);
|
||||
System.out.println(homework.getOutput());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user