A twist of a trivial sequence
Haskell, 69 bytes

x#a|x&lt;3=1|a&gt;x=a#2+(x-1)#2|mod x a&lt;1,a&lt;x=a#2*div x a#2|b&lt;-a+1=x#b
(#2)


Usage example: (#2) 1025 -> 81

The parameter a is counted up until it divides x or it reaches x (i.e. x is prime). It it one byte shorter to test for a &gt; x and add a further condition (a &lt; x) to the modulus test instead of testing for a == x, because the former binds a to x+1, which helps in the recursive call. Compare:

|a==x=(x+1)#2+(x-1)#2|mod x a&lt;1=
|a&gt;x=a#2+(x-1)#2|mod x a&lt;1,a&lt;x=