Prove that 7 is a primitive element of the prime number 7919.
Prime number decomposition is needed here. So first give the decomposed code
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 12 15:05:08 2021
@author: sangliping
"""
#素数只能被1和它本身整除,不能再被其它数整除,能被2整除的都不是素数
try:
n = 0
while True:
n = int(input("n="))
if n >=1:
break
except (ValueError):
print("请输入整数")
i = 2
frist = True
#定义为True
while n>=i:
while n%i==0:
if frist==True:
#当第一次检测,为True时,
print("=",i,end="")
#打印=号
frist = False
#这时将frist置为False,否则一直是True,因为上面初始值是True
else:
print("*",i,end="")
#打印*号
n=n//i
i += 1
Test output:
n=7918
= 2* 37* 107
So the above question becomes relatively simple.
7918 = 2 37 107
and 7 7918/2 mod 7919=7918 ≠ 1 The
same is true for 7 7918/37 mod 7919=755≠1
7 7918/107 mod 7919=5549≠1
so Ord 7919 (7)=7918 is the primitive element of 7-bit modulo 7919