From 24087c2bb4a7023d4bbf3770c638faab82b6e287 Mon Sep 17 00:00:00 2001 From: Szymon Wojciechowski Date: Wed, 30 May 2018 18:35:47 +0000 Subject: [PATCH] =?UTF-8?q?Prze=C5=9Blij=20pliki=20do=20''?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Ring.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Ring.py diff --git a/Ring.py b/Ring.py new file mode 100644 index 0000000..88345d4 --- /dev/null +++ b/Ring.py @@ -0,0 +1,48 @@ +from fractions import gcd + +class Modulo: + + def __init__(self, n): + self.n = int(n) + self.modulo_set = list(range(self.n)) + self.answer = [] + + def get_inverse_elements(self): + self.inverse_elements = [] + for i in self.modulo_set: + if gcd(i, self.n) == 1: + self.inverse_elements.append(i) + self.answer.append(self.inverse_elements) + + def get_zero_divisors(self): + self.zero_divisors = [] + for i in self.modulo_set: + for j in self.modulo_set: + if (i * j) % self.n == 0 and i != 0 and j != 0: + self.zero_divisors.append(i) + self.answer.append(list(set(self.zero_divisors))) + + def get_nilpotent_elements(self): + self.nilpotent_elements = [] + for i in self.modulo_set: + for j in range(1, len(self.inverse_elements) + 1): + if (i**j) % self.n == 0 and i != 0: + self.nilpotent_elements.append(i) + self.answer.append(list(set(self.nilpotent_elements))) + + def get_idempotent_elements(self): + self.idempotent_elements = [] + for i in self.modulo_set: + if (i*i) % self.n == i: + self.idempotent_elements.append(i) + self.answer.append(self.idempotent_elements) + + def get_all(self): + self.get_inverse_elements() + self.get_zero_divisors() + self.get_nilpotent_elements() + self.get_idempotent_elements() + return self.answer + +s = Modulo(input("Enter n: ")) +print(s.get_all())