HP Forums

Full Version: Puzzle: sequence without multiples of 3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
What is the simplest formula that can generate: 1,2, 4,5, 7,8, 10,11 ... ?

In other words, sequence never generate multiples of 3.

f(1) = 1, f(2) = 2, f(3) = 4, f(4) = 5, f(5) = 7, f(6) = 8 ...

What is f(10^6) ?
f(10^6) = (3*333334-2)
k=333334
(09-13-2019 09:02 PM)Voldemar Wrote: [ -> ]f(10^6) = (3*333334-2)
k=333334

No, f(k) = k-th numbers from the sequence 1,2, 4,5, 7,8, 10,11, 13,14, ...

Example, f(10) = 14
f(n) = floor((n-1)*1.5)+1

This wouldn't be much of a puzzle if the most obvious formula happened to be the solution, but I thought I'd get it out of the way. As a baseline, if you will.

UPDATE to add the answer to the second question: f(10^6) = 1,499,999
A simple program to generate the sequence, which is A001651:

Code:

\<< \-> n
  \<< 1 1 n
    START DUP 1 + DUP 2 +
    NEXT n 2 * 1 + \->LIST
  \>>
\>>

Returns 2n+1 terms. Not much use to compute f(10^6) though. Smile
Hi, Thomas Okken

You got it!

I saw the formula from a book review, The Irrationals, by Julian Havil

The formula itself is trivial, but the procedure to get it can be used for complicated sequences.

Example: for non-squares sequence
Code:
F=n²   1  4  9 16 25 36 49 64 81
n      1  2  3  4  5  6  7  8  9
f=n²-n 0  2  6 12 20 30 42 58 72
f*     1  1  2  2  2  2  3  3  3
n + f* 2  3  5  6  7  8 10 11 12

This assumed f is non-decreasing function.
f* is max k such that f(k) < n, thus we have 2x1, 4x2, 6x3, 8x4 ...

→ f*(n) = floor(√(n) + 0.5)
→ non_squares(n) = n + f* = n + floor(√(n) + 0.5)
INT((3*N-1)/2) for HP 38G.
Here is the HP-12C code that produce f(n), f(n) < 10^10

Code:
Enter Enter Enter
2 / INTG 2 × − Enter ×    ; n%2
2 − + 2 ÷ +               ; f(n) = n + (n + n%2 − 2) / 2
Reference URL's