A twist of a trivial sequence Introduction
Consider a sequence of integers \$f\$ defined as follows:

\$f(2) = 2\$
If \$n\$ is an odd prime, then \$f(n) = \frac{f(n-1) + f(n+1)}2\$
If \$n = p\cdot q\$ is composite, then \$f(n) = f(p)\cdot f(q)\$

It's not very hard to see that \$f(n) = n\$ for every \$n \ge 2\$, and thus computing \$f\$ wouldn't be a very interesting challenge.
Let's make a twist to the definition: halve the first case and double the second case.
We get a new sequence \$g\$ defined as follows:

\$g(2) = 1\$
If \$n\$ is an odd prime, then \$g(n) = g(n-1) + g(n+1)\$
If \$n = p\cdot q\$ is composite, then \$g(n) = g(p)\cdot g(q)\$

The task
Your task is to take an integer \$n \ge 2\$ as input, and produce \$g(n)\$ as output.
You don't have to worry about integer overflow, but you should be able to compute \$g(1025) = 81\$ correctly, and your algorithm should theoretically work for arbitrarily large inputs.
You can write a full program or a function.
The lowest byte count wins.
Example
I claimed above that \$g(1025) = 81\$, so let's compute it by hand.
The prime factorization of 1025 gives
1025 = 5*5*41 =&gt; g(1025) = g(5)*g(5)*g(41)

Since 41 is prime, we get
g(41) = g(40) + g(42)

Next, we compute the prime factorizations of 40 and 42:
40 = 2*2*2*5 =&gt; g(40) = g(2)*g(2)*g(2)*g(5) = g(5)
42 = 2*3*7 =&gt; g(42) = g(2)*g(3)*g(7) = g(3)*g(7)

For these small primes we get
g(3) = g(2) + g(4) = 1 + 1 = 2
g(5) = g(4) + g(6) = 1 + 2 = 3
g(7) = g(6) + g(8) = 2 + 1 = 3

This means that
g(41) = g(40) + g(42) = g(5) + g(3)*g(7) = 3 + 2*3 = 9

and
g(1025) = g(5)*g(5)*g(41) = 3*3*9 = 81

Test cases
Here are the values of \$g\$ up to 50.
2 -&gt; 1
3 -&gt; 2
4 -&gt; 1
5 -&gt; 3
6 -&gt; 2
7 -&gt; 3
8 -&gt; 1
9 -&gt; 4
10 -&gt; 3
11 -&gt; 5
12 -&gt; 2
13 -&gt; 5
14 -&gt; 3
15 -&gt; 6
16 -&gt; 1
17 -&gt; 5
18 -&gt; 4
19 -&gt; 7
20 -&gt; 3
21 -&gt; 6
22 -&gt; 5
23 -&gt; 7
24 -&gt; 2
25 -&gt; 9
26 -&gt; 5
27 -&gt; 8
28 -&gt; 3
29 -&gt; 9
30 -&gt; 6
31 -&gt; 7
32 -&gt; 1
33 -&gt; 10
34 -&gt; 5
35 -&gt; 9
36 -&gt; 4
37 -&gt; 11
38 -&gt; 7
39 -&gt; 10
40 -&gt; 3
41 -&gt; 9
42 -&gt; 6
43 -&gt; 11
44 -&gt; 5
45 -&gt; 12
46 -&gt; 7
47 -&gt; 9
48 -&gt; 2
49 -&gt; 9
50 -&gt; 9
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=