任意给定两个素数p和q,p!= q,记 N = p * q ,构造Zn*,
问(编程解决):
1、是否每个元素都有inverse?是否成群? 2、这个集合有多少元素?
count = 1
while (count):
n = int(input("输入一个质数:"))
for i in range(2, n):
if n % i == 0:
print(" %d 这不是一个质数!" % n)
break
else:
return n
def CommonFactor(a,b):
if a<b:
t = a
a = b
b = t
while(a%b):
t = b
b = a % b
a = t
return b
def is_inverse(list,n):
mark=1
for i in range(0,len(list)):
count=1
for j in range(0,len(list)):
if((list[i]*list[j])%n==1):
count = 0
print("%s存在逆元%s"%(list[i],list[j]),end=" ")
if count:
print("%s不存在逆元"%(list[i]),end=" ")
mark=0
print()
if(mark):
print("任何元素都有逆元")
return mark
def is_closed(list,n):
mark=1
for i in range(0, len(list)):
for j in range(0, len(list)):
count=0
for k in range(0, len(list)):
if((list[i]*list[j])%n == list[k]):
count=1
num=list[k]
if count:
print("%s*%s封闭值为%s"%(list[i],list[j],num))
else:
print("%s*%s不封闭"%(list[i],list[j]))
mark=0
return mark
def main():
p=isprime()
count=1
while(count):
q=isprime()
if not q==p:
count=0
else:
print("与第一个质数相同,请重新输入")
n=p*q
list=[]
for i in range(1,n):
k=CommonFactor(i,n)
if k==1:
list.append(i)
for i in range(0,len(list)):
print(list[i],end=" ")
print()
a=is_inverse(list,n)
b=is_closed(list,n)
if a==1 and b==1:
print("任意元素都有逆元且运算封闭,成群")
print("群元素有%s个"%(len(list)))
elif a==0:
print("存在元素没有逆元,不成群")
elif b==0: