login
A182665
Greatest x < n such that n divides x*(x-1).
7
0, 1, 1, 1, 1, 4, 1, 1, 1, 6, 1, 9, 1, 8, 10, 1, 1, 10, 1, 16, 15, 12, 1, 16, 1, 14, 1, 21, 1, 25, 1, 1, 22, 18, 21, 28, 1, 20, 27, 25, 1, 36, 1, 33, 36, 24, 1, 33, 1, 26, 34, 40, 1, 28, 45, 49, 39, 30, 1, 45, 1, 32, 36, 1, 40, 55, 1, 52, 46, 56, 1, 64, 1, 38, 51, 57, 56, 66, 1, 65, 1, 42, 1, 64, 51, 44, 58, 56, 1, 81, 78, 69, 63, 48, 76, 64, 1, 50, 55
OFFSET
1,6
COMMENTS
a(n) = 1 iff n is in A246655. - Robert Israel, Jan 13 2015
FORMULA
a(n) = n - A344005(n). - Antti Karttunen, May 19 2022
EXAMPLE
a(6) = 4 because 6 divides 4*3=12 but does not divide 5*4=20.
MAPLE
A:= proc(n)
max(map(u -> u*modp(1/u, n/u),
map(t -> mul(s[1]^s[2], s = t),
combinat[powerset](ifactors(n)[2]))))
end proc;
seq(A(n), n=1..100);
MATHEMATICA
a[n_] := Module[{x}, Max[x /. {ToRules[Reduce[Mod[x*(x-1), n] == 0 && Mod[x*(x+1), n] != 0, x, Integers] /. C[_] -> 0]}]]; a[1] = 0; a[2] = 1; Table[a[n], {n, 1, 100}] (* Jean-François Alcover, Mar 04 2014 *)
PROG
(PARI) A182665(n) = forstep(x=n-1, 0, -1, if(!((x*(x-1))%n), return(x))); \\ Antti Karttunen, Jun 12 2022
(Python 3.8+)
from itertools import combinations
from math import prod
from sympy import factorint
from sympy.ntheory.modular import crt
def A182665(n):
if n == 1:
return 0
plist = tuple(p**q for p, q in factorint(n).items())
return 1 if len(plist) == 1 else n-int(min(min(crt((m, n//m), (0, -1))[0], crt((n//m, m), (0, -1))[0]) for m in (prod(d) for l in range(1, len(plist)//2+1) for d in combinations(plist, l)))) # Chai Wah Wu, Jun 12 2022
CROSSREFS
Cf. A246655, A345992 [= gcd(a(n), n) = gcd(a(n), A344005(n))], A354919, A354920 (parity), A354921 (positions of odd terms), A354922 (of even terms).
Sequence in context: A306264 A321647 A323410 * A131299 A360911 A363977
KEYWORD
nonn,easy
AUTHOR
Robert Israel, Dec 23 2012
STATUS
approved