Are you lost yet?
Jelly, 30 29 27 25 bytes
Saved 2 bytes thanks to @Dennis notifying me about Æd
, and another 2 bytes for combining the two chains.
RUð÷‘Ċ×µ/
‘Ç_ÇH0Æd=¥1#×3+
Try it online!
This was probably the most fun I've ever had with Jelly. I started from the second line, which calculates fn from n using the formula on OEIS, and is quite beautiful.
Explanation
RUð÷‘Ċ×µ/ Helper link to calculate Fn. Argument: n R Get numbers [1..n] U Reverse / Reduce by "round up to next 2 multiples": ÷ Divide by the next number ‘ Increment to skip a multiple Ċ Ceil (round up) × Multiply by the next number ‘Ç_ÇH0Æd=¥1#×3+ Main link. Argument: n ‘ Increment n Ç Calculate Fn+1 Ç Calculate Fn _ Subtract H Divide by 2 0 1# Starting from 0, find the first candidate for (an-n)/3 that satisfies... Æd σ0((an-n)/3) = = (Fn+1-Fn)/2 ×3 Multiply by 3 to turn (an-n)/3 into an-n + Add n to turn an-n into an
Python 2, 121 119 118 bytes
n=input();r=range(1,4**n);d=s,=r*1,
for k in r:del s[k::k+1];d+=sum(k%j<1for j in r)*2,
print d.index(s[n]-s[n-1])*3+n
Run time should be roughly O(16n) with O(4n) memory usage. Replacing 4**n
with 5<<n
– which I think is sufficient – would improve this dramatically, but I'm not convinced that it works for arbitrarily large values of n.
Try it online!
Asymptotic behavior and upper bounds of an
Define bn as (an - n)/3, i.e., the smallest positive integer k such that σ0(k) = ½(fn+1 - fn).
As noted on the OEIS page, fn ~ ¼πn2, so fn+1 - fn ~ ¼π(n + 1)2 - ¼πn2 = ¼π(2n + 1) ~ ½πn.
This way, ½(fn+1 - fn) ~ ¼πn. If the actual number is a prime p, the smallest positive integer with p divisors is 2p-1, so bn can be approximated by 2cn, where cn ~ ¼πn.
Therefore bn < 4n will hold for sufficiently large n, and given that 2¼πn < 2n << (2n)2 = 4n, I'm confident there are no counterexamples.
How it works
n=input();r=range(1,4**n);d=s,=r*1,
This sets up a few references for our iterative process.
n is the user input: a positive integer.
r is the list [1, ..., 4n - 1].
s is a copy of r.
Repeating the list once with
r*1
creates a shallow copy, so modifying s won't modify r.d is initialized as the tuple (s).
This first value is not important. All others will hold divisor counts of positive integers.
for k in r:del s[k::k+1];d+=sum(k%j<1for j in r)*2,
For each integer k from 1 to 4n - 1, we do the following.
del s[k::k+1]
takes every (k + 1)th integer in s – starting with the (k + 1)th – and deletes that slice from s.This is a straightforward way of storing an initial interval of the Flavius Josephus sieve in s. It will compute much more than the required n + 1 initial terms, but using a single
for
loop to update both s and d saves some bytes.d+=sum(k%j<1for j in r)*2,
counts how many elements of r divide k evenly and appends 2σ0(k) to d.Since d was initialized as a singleton tuple, 2σ0(k) is stored at index k.
print d.index(s[n]-s[n-1])*3+n
This finds the first index of fn+1 - fn in d, which is the smallest k such that 2σ0(k) = fn+1 - fn, then computes an as 3k + 1 and prints the result.
Java 8, 336, 305, 303, 287, 283 279 bytes
57 bytes removed thanks to Kritixi Lithos
Golfed
class f{static int g(int s,int N){return s<1?N+1:g(s-1,N+N/s);}static int h(int k){int u=0,t=1,i;for(;u!=(g(k,k)-g(k,k-1))/2;t++)for(i=1,u=0;i<=t;)if(t%i++<1)u++;return 3*t-3+k;}public static void main(String[]a){System.out.print(h(new java.util.Scanner(System.in).nextInt()));}}
Ungolfed
class f {
static int g(int s,int N){return s < 1 ? N + 1 : g(s - 1, N + N / s);}
static int h(int k) {
int u = 0, t = 1, i;
// get the first number with v divisors
while(u != (g(k, k) - g(k, k - 1))/2){
u = 0;
for (i = 1; i <= t; i++)
if (t % i < 1) u++;
t++;
}
// 3*(t-1)+k = 3*t+k-3
return 3 * t + k - 3;
}
public static void main(String[] a) {
System.out.print(h(new java.util.Scanner(System.in).nextInt()));
}
}