OFFSET
1,1
COMMENTS
Numbers m such that the base-5 representation of (2*m-1) starts with 3 or 4 or ends with 0.
First differences give a run of 5^i 1's followed by a run of 5^i 5's, for i >= 0.
LINKS
FORMULA
For n in the range (5^i + 1)/2 <= n < (3*5^i + 1)/2, for i >= 0:
a(n) = n + 5^i.
a(n+1) = 1 + a(n).
Otherwise, for n in the range (3*5^i + 1)/2 < n <= (5*5^i + 1)/2, for i >= 0:
a(n) = 5*(n - 5^i) - 2.
a(n+1) = 5 + a(n).
EXAMPLE
a(7) = 12 because (5^1 + 1)/2 <= 7 < (3*5^1 + 1)/2, hence a(7) = 7 + 5^1 = 12;
a(11) = 28 because (3*5^1 + 1)/2 <= 11 < (5*5^1 + 1)/2, hence a(11) = 5*(11 - 5^1) - 2 = 28.
MATHEMATICA
a[n_] := Module[{n2 = 2n, p}, p = 5^Floor@Log[5, n2]; If[n2 < 3p, n+p, 5(n-p)-2]];
Table[a[n], {n, 1, 100}] (* Jean-François Alcover, Sep 22 2023, after Kevin Ryde *)
PROG
(PARI) a(n) = my(n2=n<<1, p=5^logint(n2, 5)); if(n2 < 3*p, n+p, 5*(n-p)-2); \\ Kevin Ryde, Apr 18 2022
(C++)
/* program used to generate the b-file */
#include<iostream>
using namespace std;
int main(){
int cnt1=1, flag=0, cnt2=1, a=2;
for(int n=1; n<=10000; n++) {
cout<<n<<" "<<a<<endl;
if(cnt2==cnt1) {
flag=1-flag, cnt1=1;
if(flag) a+=1;
else {
a+=5;
cnt2*=5;
}
}
else {
cnt1++;
a+=(flag?5:1);
}
}
return 0;
}
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Yifan Xie, Jul 15 2022
STATUS
approved