From 1b910bbfb4e79b53fb826012bb238457f9894a28 Mon Sep 17 00:00:00 2001 From: Krystian Madra Date: Thu, 28 Jun 2018 00:35:28 +0200 Subject: [PATCH] polynomials division --- Main.java | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Main.java b/Main.java index 8e6c43b..556eccd 100644 --- a/Main.java +++ b/Main.java @@ -200,5 +200,49 @@ public class Main { } return elements; } + + public static LinkedList dividePolynomials(LinkedList p1, LinkedList p2, int mod) { + + LinkedList result = new LinkedList(p1); + LinkedList tmpP = new LinkedList(); + + 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; + } } \ No newline at end of file