Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
3feef9f4af | |||
1d1b6f026a | |||
add5ee3825 | |||
9ce74ff658 | |||
2542773fa7 |
@ -16,4 +16,4 @@ Termin: 07.06
|
||||
> Output: `[[0,1,0,0,1,1,1], [1,1], [1,1]]`
|
||||
|
||||
> Input: `6, [2,1,0,2,1,3], [1,0,0,5]`
|
||||
> Output: `[[3,1,0,5,0,1,4,5,5], [5,2,1], DivisionError]`
|
||||
> Output: `[[2,1,0,0,0,3,4,5,3], [4,2,3], DivisionError]`
|
||||
|
57
zad1.py
Normal file
57
zad1.py
Normal file
@ -0,0 +1,57 @@
|
||||
def odwracalny(i,n):
|
||||
for x in range(n):
|
||||
if((x * i) % n == 1):
|
||||
return True
|
||||
return False
|
||||
|
||||
def el_odwracalne(n):
|
||||
lista = []
|
||||
for i in range(n):
|
||||
if(odwracalny(i,n)):
|
||||
lista.append(i)
|
||||
return(lista)
|
||||
|
||||
def dzieli_zero(i,n):
|
||||
for x in range(1,n):
|
||||
if((x * i) % n == 0):
|
||||
return True
|
||||
return False
|
||||
|
||||
def dzielniki_zera(n):
|
||||
lista = []
|
||||
for i in range(n):
|
||||
if(dzieli_zero(i,n)):
|
||||
lista.append(i)
|
||||
return(lista)
|
||||
|
||||
def nilpotent(i,n):
|
||||
for x in range(1,n):
|
||||
if((i**x) % n == 0):
|
||||
return True
|
||||
return False
|
||||
|
||||
def el_nilpotentne(n):
|
||||
lista = []
|
||||
for x in range(n):
|
||||
if(nilpotent(x,n)):
|
||||
lista.append(x)
|
||||
return(lista)
|
||||
|
||||
|
||||
def el_idempotentne(n):
|
||||
lista = []
|
||||
for x in range(n):
|
||||
if((x*x) % n == x):
|
||||
lista.append(x)
|
||||
return(lista)
|
||||
|
||||
def main():
|
||||
n = int(input("Podaj n: "))
|
||||
print("Z/"+str(n))
|
||||
print("elementy odwracalne "+str(el_odwracalne(n)))
|
||||
print("dzielniki zera "+str(dzielniki_zera(n)))
|
||||
print("elementy nilpotentne "+str(el_nilpotentne(n)))
|
||||
print("elementy idempotentne "+str(el_idempotentne(n)))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
71
zad2.py
Normal file
71
zad2.py
Normal file
@ -0,0 +1,71 @@
|
||||
import sys
|
||||
import ast
|
||||
|
||||
def modulo(x,n):
|
||||
for i in range(len(x)):
|
||||
x[i] = x[i] % n
|
||||
return x
|
||||
|
||||
def iloczyn(f,g,n):
|
||||
wynik = [0]*(len(f)+len(g)-1)
|
||||
for i in range(len(f)):
|
||||
for j in range(len(g)):
|
||||
wynik[i+j] += f[i]*g[j]
|
||||
return modulo(wynik,n)
|
||||
|
||||
def liczmod(a,x,n):
|
||||
for i in range(n):
|
||||
if( (a*i) % n == x):
|
||||
return(i)
|
||||
return(-1)
|
||||
|
||||
def sumujmod(a,b,n):
|
||||
if(len(a) < len(b)):
|
||||
wynik = b
|
||||
for i in range(len(a)):
|
||||
wynik[i] += a[i]
|
||||
else:
|
||||
wynik = a
|
||||
for i in range(len(b)):
|
||||
wynik[i] += b[i]
|
||||
return modulo(wynik,n)
|
||||
|
||||
def redukcjazer(x):
|
||||
while x and x[-1] is 0:
|
||||
x.pop()
|
||||
return(x)
|
||||
|
||||
def klasaReszt(f,g,n):
|
||||
wynik = f
|
||||
mnoznik = [0] * (len(f)-len(g)+2)
|
||||
for i in range(len(f)):
|
||||
if(liczmod(g[len(g)-1],wynik[len(f)-1-i],n) == -1):
|
||||
return("DivisionError")
|
||||
if(i > len(f)-len(g)):
|
||||
return redukcjazer(modulo(wynik,n))
|
||||
else:
|
||||
mnoznik.pop()
|
||||
mnoznik.pop()
|
||||
mnoznik.append(-1*liczmod(g[len(g)-1],wynik[len(f)-1-i],n))
|
||||
wynik = sumujmod(wynik, iloczyn(g, mnoznik ,n) ,n)
|
||||
|
||||
def nwd(a,b,n):
|
||||
while(b != []):
|
||||
if(klasaReszt(a,b,n)):
|
||||
return "DivisionError"
|
||||
c = klasaReszt(a,b,n)
|
||||
a = b
|
||||
b = c
|
||||
return modulo(a,n)
|
||||
|
||||
def main():
|
||||
n = int(sys.argv[1])
|
||||
f = ast.literal_eval(sys.argv[2])
|
||||
g = ast.literal_eval(sys.argv[3])
|
||||
|
||||
print(iloczyn(f,g,n))
|
||||
print(klasaReszt(f,g,n))
|
||||
print(nwd(f,g,n))
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user