From b0323052f75b0c924a689bf3a0ce0f77f6c96d0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksy=20Wr=C3=B3blewski?= Date: Wed, 30 May 2018 17:44:28 +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 python hw.py --- hw.py | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 hw.py diff --git a/hw.py b/hw.py new file mode 100644 index 0000000..029b759 --- /dev/null +++ b/hw.py @@ -0,0 +1,47 @@ +from fractions import gcd +class Modulo: + def __init__(self, n): + self.elems = list(range(n)) + self.n = n + self.reversibles = self.get_reversibles() + self.idempotent = self.get_idempotent() + self.zero_divisors = self.get_zero_divisors() + self.nilpotent = self.get_nilpotent() + '''elementy odwracalne to te, ktorych nwd z n jest rowne 1''' + def get_reversibles(self): + return list(filter(lambda x: gcd(x, self.n) == 1, self.elems)) + + '''nie rozwazamy elementow odwracalnych ani liczby 0 + #dzielnik zera nie moze byc elementem odwracalnym''' + def get_zero_divisors(self): + potential_zeros = [ elem for elem in self.elems if elem not in self.reversibles ][1:] + results = [] + for elem in potential_zeros: + for elem2 in potential_zeros: + if (elem * elem2) % self.n == 0: + results.append(elem) + break + return list(results) + + def get_idempotent(self): + '''element idempotentny => a^2 przystaje do a''' + return list(filter(lambda x: x*x % self.n == x, self.elems)) + + def get_nilpotent(self): + '''jesli pierscien nie zawiera dzielnikow zera, to nie zawiera takze elementow + nilpotentnych; wystarczy sprawdzic wsrod dzielnikow zera ''' + potential_nils = self.zero_divisors + phi = len(self.reversibles) #funkcja fi + results = [] + for elem in potential_nils: + for i in range(1, phi+1): + if elem**i % self.n == 0: + results.append(elem) + break + return results + +def main(): + m = Modulo(int(input())) + print([m.reversibles, m.zero_divisors, m.nilpotent, m.idempotent]) +if __name__ == '__main__': + main() -- 2.20.1