1
1
forked from kalmar/DALGLI0
DALGLI0/Ring.py

49 lines
1.6 KiB
Python

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())