How i can solve the problem of primitive root?
5 次查看(过去 30 天)
显示 更早的评论
Hello matalb community.
Why not all the values of p shows?, where there are (NaN) values in the array of y
p = 54497; % p is a prime number
a=3; % a is a primitive root to p
for i = 1:p-1
y(i) = mod(power(a,i),p);
end
0 个评论
采纳的回答
John D'Errico
2022-11-26
编辑:John D'Errico
2022-11-26
What you mistake is that a and p are represented as DOUBLES. Can you compute a number as you want to do? What happens?
a = 3;
p = 54497;
x = 21666;
power(a,x)
Do you see there are precision problems? Double precision arithmetic overflows when you try to compute those large powers. And then mod must fail.
Instead, while you CAN use syms to compute the moduli, it is far better to learn about the powermod function.
powermod(3,x,p)
Powermod EFFICIENTLY compute the modulus here, without ever computing the number a^x, and so we won't see an overflow, at least not until the modulus gets too large.
y = zeros(100,1);
for i = 1:100
y(i) = powermod(a,i,p);
end
table((1:100)',y)
However, it sounds as if you want to know how to solve for the primitive roots modulo some prime.
In there, you would read:
"In particular, for a to be a primitive root modulo n, φ(n) has to be the smallest power of a that is congruent to 1 modulo n."
We would also learn that
If a is a primitive root modulo a prime p, then mod(a.^(p-1)/2,p) == p-1.
Remember, for n prime, the Euler Totient function has the property that phi(n)==n-1.
What, for example, are the primitive roots of 11? This will be the set of integers r in the interval [2,n-2], such that
powermod(r,(n-1)/2,n) == -1 == n-1 (mod n)
n = 11;
rtest = 2:n-2;
primitiveroots = rtest(powermod(rtest,(n-1)/2,n) == n-1)
And on that wiki page, we would see the primitive roots of 11 are [2,6,7,8].
Finally, we would see this comment:
No simple general formula to compute primitive roots modulo n is known.
So, at best, for a large prime modulus, the above computation seems about the best you can do.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Number Theory 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!