Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.
%I #40 Jan 20 2025 18:41:28
%S 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,
%T 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,
%U 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
%N Greatest x < n such that n divides x*(x-1).
%C a(n) = 1 iff n is in A246655. - _Robert Israel_, Jan 13 2015
%H Robert Israel, <a href="/A182665/b182665.txt">Table of n, a(n) for n = 1..10000</a>
%H <a href="http://math.stackexchange.com/questions/264290/division-into-xx-1/264307#264307">Question on math.stackexchange.com</a>
%F a(n) = n - A344005(n). - _Antti Karttunen_, May 19 2022
%e a(6) = 4 because 6 divides 4*3=12 but does not divide 5*4=20.
%p A:= proc(n)
%p max(map(u -> u*modp(1/u,n/u),
%p map(t -> mul(s[1]^s[2],s = t),
%p combinat[powerset](ifactors(n)[2]))))
%p end proc;
%p seq(A(n),n=1..100);
%t 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 *)
%o (PARI) A182665(n) = forstep(x=n-1,0,-1,if(!((x*(x-1))%n),return(x))); \\ _Antti Karttunen_, Jun 12 2022
%o (Python)
%o from itertools import combinations
%o from math import prod
%o from sympy import factorint
%o from sympy.ntheory.modular import crt
%o def A182665(n):
%o if n == 1:
%o return 0
%o plist = tuple(p**q for p, q in factorint(n).items())
%o 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
%Y Cf. A246655, A345992 [= gcd(a(n), n) = gcd(a(n), A344005(n))], A354919, A354920 (parity), A354921 (positions of odd terms), A354922 (of even terms).
%K nonn,easy,changed
%O 1,6
%A _Robert Israel_, Dec 23 2012