9
1
Consider the integers modulo q
where q
is prime, a generator is any integer 1 < x < q
so that x^1, x^2, ..., x^(q-1)
covers all q-1
of the integers between 1
and q-1
. For example, consider the integers modulo 7 (which we write as Z_7
). Then 3, 3^2 mod 7 = 2, 3^3 = 27 mod 7 = 6, 3^4 = 81 mod 7 = 4, 3^5 = 243 mod 7 = 5, 3^6 = 729 mod 7 = 1
covers all the values 3, 2, 6, 4, 5, 1
covers all the integers 1..6
as required.
The task is to write code that takes an input n
and outputs a generator for Z_n
. You cannot use any builtin or library that does this for you of course.
The only restriction on the performance of your code is that you must have tested it to completion with n = 4257452468389
.
Note that 2^n
means 2
to the power of n
. That is ^
represents exponentiation.
Hmm...
1 < x < q
makes the challenge a lot easier imo. – Erik the Outgolfer – 2017-07-02T11:49:39.107@EriktheOutgolfer I am not sure I know what you mean? Those are just all the distinct integers that are not 0 or 1. – None – 2017-07-02T11:52:41.657
I mean that it's easier than what many probably think...or maybe some inactive moment on PPCG. – Erik the Outgolfer – 2017-07-02T11:53:53.183
3But I think that requiring people to test it to completion to a large number is unnecessary...basically tio would just memory-error. – Erik the Outgolfer – 2017-07-02T11:56:38.337
@Lembik Is there any case where there is no generator for a certain number? Some test cases would be good. – Mr. Xcoder – 2017-07-02T11:58:59.673
@Mr.Xcoder No. This is because
q
is prime. – None – 2017-07-02T11:59:17.727@EriktheOutgolfer The point of that test is to exclude really naive solutions without specify exactly how efficient the solution should be. – None – 2017-07-02T12:00:41.587
@Lembik you need a tag for that probably, that's not normal code-golf – Stephen – 2017-07-02T12:02:56.557
@StepHen Agree, [tag:restricted-complexity]. – Mr. Xcoder – 2017-07-02T12:03:23.810
@Mr.Xcoder It was suggested to me in chat that this is an alternative way of doing this. It has some advantages we can discuss in chat. – None – 2017-07-02T12:04:30.050
This is just finding a generator of the group of units of Z_p, right? Or do I need to refresh my abstract algebra notes... – Giuseppe – 2017-07-02T12:28:35.757
@Giuseppe Yes although notice that
p
is prime in this case. – None – 2017-07-02T12:30:49.597Would the curator of SCP-155 care to participate? – Joshua – 2017-07-02T16:16:03.947