%I
%S 0,1,1,2,1,2,1,4,3,2,1,4,1,2,1,6,1,4,1,6,3,2,1,8,5,2,3,4,1,4,1,6,1,2,
%T 1,8,1,2,3,12,1,8,1,4,3,2,1,12,7,6,1,6,1,4,5,8,3,2,1,12,1,2,9,10,1,4,
%U 1,6,1,4,1,16,1,2,5,4,1,8,1,20,9,2,1,16,1,2,1,8,1,8,1,4,3,2,1,12,1,8,3,14
%N Number of k with k^n=1 (mod n) and k^k=k (mod n); related to some groups of order n
%C Given integers n and k, consider the operation
%C o_k: Z_n x Z_n > Z_n, (a, b) > a + k^a * b (mod n).
%C (Z_n, o_k) is a group if k^n == 1 (mod n) and k^k == k (mod n).
%C The first condition is necessary to get the definition welldefined.
%C The second condition is necessary for the associative property.
%C a(n) gives the number of different k out of {1, 2, ..., n1} that comply the conditions.
%C E.g., for n = 4, k = 1 (or, what is the same, k = 3) results in the Klein fourgroup. (a o_3 b := a + (1)^a * b (mod 4).)
%C Note that different k can result in groups that are isomorphic to each other.
%C The neutral element is always 0.
%C The inverse element to a is always a*k^(a) (mod n).
%H Antti Karttunen, <a href="/A270120/b270120.txt">Table of n, a(n) for n = 1..65537</a>
%H Alfred Heiligenbrunner, <a href="/A270120/a270120_1.txt">A270120 Further examples and how the small groups were named</a>
%H OEIS Wiki, <a href="http://oeis.org/wiki/Number_of_groups_of_order_n">OEIS Wiki Groups of order n</a>
%e a(4) = 2, because in Z_4, k == 1 and k == 3 are the only number out of {0, 1, 2, 3} with conditions k^k==k mod n and k^n==1 mod n.
%e a(8) = 4, because k can be out of {1, 3, 5, 7}.
%e a(18) = 4, because k can be out of {1, 7, 13, 17}.
%e If n is even, k == 1 (or, equivalently, k == n1) is always to be counted. This group is isomorphic to the Dihedral group D_(n/2), with generating elements 1 and 2.
%e The following table shows the first results with n, k and the name of the group (due to A. D. Thomas and G. V. Wood: 'Group Tables', found by comparing the elementorders).
%e Note that for n=8, k=1 and k=5 result in Z8. None of the k results in Z2 x Z4 or in Z2 x Z2 x Z2.
%e Note that for n=9 all k are isomorphic to Z9, none to Z3 x Z3.
%e n=2, k=1: Z2
%e n=3, k=1: Z3
%e n=4, k=1: Z4
%e n=4, k=3: Z2 x Z2
%e n=5, k=1: Z5
%e n=6, k=1: Z6
%e n=6, k=5: D3
%e n=7, k=1: Z7
%e n=8, k=1: Z8
%e n=8, k=3: Q4
%e n=8, k=5: Z8
%e n=8, k=7: D4
%e n=9, k=1: Z9
%e n=9, k=4: Z9
%e n=9, k=7: Z9
%e n=10, k=1: Z10
%e n=10, k=9: D5
%e ...
%t Table[Length[ Select[Range[1, n1], ((GCD[n, #  1] > 1) && (PowerMod[#, n, n] == 1) && (PowerMod[#, #  1, n] == 1)) &]], {n, 1, 100}]
%o (PARI) a(n) = sum(k=1, n1, (Mod(k,n)^n == 1) && (Mod(k,n)^k == k)); \\ _Michel Marcus_, Mar 12 2016
%Y Cf. A000001 (number of groups of order n).
%K nonn,easy
%O 1,4
%A _Alfred Heiligenbrunner_, Mar 11 2016
