forked from kalmar/DALGLI0
Prześlij pliki do ''
python hw.py
This commit is contained in:
parent
16f4649ea6
commit
b0323052f7
47
hw.py
Normal file
47
hw.py
Normal file
@ -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()
|
Loading…
Reference in New Issue
Block a user