polynomials division
This commit is contained in:
parent
935fba7d15
commit
1b910bbfb4
44
Main.java
44
Main.java
@ -200,5 +200,49 @@ public class Main {
|
||||
}
|
||||
return elements;
|
||||
}
|
||||
|
||||
public static LinkedList<Integer> dividePolynomials(LinkedList<Integer> p1, LinkedList<Integer> p2, int mod) {
|
||||
|
||||
LinkedList<Integer> result = new LinkedList<Integer>(p1);
|
||||
LinkedList<Integer> tmpP = new LinkedList<Integer>();
|
||||
|
||||
int stP1 = p1.size();
|
||||
int stP2 = p2.size();
|
||||
|
||||
if(p1.size() < p2.size()) {
|
||||
System.out.println("NIE DA SIE");
|
||||
return result;
|
||||
}
|
||||
|
||||
int tmp;
|
||||
|
||||
// sprawdzenie czy reszta jest mniejszego stopnia
|
||||
while(stP1 >= stP2) {
|
||||
|
||||
tmp = multiplier(p2.getLast(), result.getLast(), mod);
|
||||
|
||||
// przesuniecie
|
||||
tmpP = shiftList(p2,stP1 - stP2);
|
||||
|
||||
|
||||
if(tmp != 0) {
|
||||
// mnoznie przez liczbe
|
||||
tmpP = multiplyPolynomial(tmpP,tmp);
|
||||
}
|
||||
|
||||
// dzielenie modulo
|
||||
tmpP = modPolynomial(mod,tmpP);
|
||||
|
||||
// odejmowanie
|
||||
result = substractPolynomials(result,tmpP);
|
||||
|
||||
result = modPolynomial(mod, result);
|
||||
|
||||
// st po odjeciu
|
||||
stP1 = result.size();
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user