0

I have two quick questions.

Is there a way to quickly verify that a number is $3n+2$, i was thinking using modulus (if thats possible?), but based on the binary expansion I dont see to find a definite pattern at the moment.

The number should be part of the following sequence $\{2,5,8,11,14,17,20,...\}$. Ive sometimes seen that an even number is defined as $n=2k$ for $k\in\mathbb{Z^+}$.

Can i define a number that is $3n+2$ as $n=3k+2$ for $k\in\mathbb{Z^+}$?

And the other question was how to perform an operation based on that number (by verifying it first), for example if the number is $3k+2$ then add $1$, else subtract $1$, or something like this.

If that was not clear then, I want to do like Collatz function: if a number is odd then $3n+1$, else if a number is even $n/2$.

Example:

$$C(n) = \begin{cases} 3n + 1 &\quad \text{ if $n$ is odd} \\ n/2 &\quad \text{ if $n$ is even} \end{cases}$$

I would have to:

$$C(n) = \begin{cases} n + 1 &\quad \text{ if $n = 3n+2$} \\ n - 1 &\quad \text{ if $n \neq 3n+2$} \end{cases}$$

But I feel its not quite proper.

2 Answers2

2

*******The quick trick for divisibility by 3 is to check if the sum of the digits is divisible by 3. To prove this think about the expansion of digits as $n_kn_{k-1}\cdots n_2n_1n_0=\sum_{i=0}^k n_i10^{k}$ then using modular arithmetic. The same approach will work for checking $3k+2$, just think what must the sum of the digits imply?

^^ wrong base sorry.********

Yep, just think modular arithmetic on $2^k \pmod{3}$, so $2^0=1$, $2^1=-1$, so $2^k=(2^1)^k\equiv (-1)^k\pmod{3}$, so you can do an add/subtract process

Ex: 29 is $11101\rightarrow 1-0+1-1+1=2$ so $29\equiv 2\pmod{3}$.

In this process I go right to left since it always starts us with $2^0$ and we don't cause an indexing error on size of number (# of digits in binary expansion). This may be inefficient in computing -- idk how reading long arrays works etc. lol but i'm sure if it isnt you can easily just use length to go left-right to be more efficient.

oshill
  • 313
  • 1
  • 8
0

Casting out threes in binary radix works the same way as casting out elevens in decimal

$\!\!\begin{align}\bmod 3\!:\,\ \color{#c00} {2\equiv -1}\,\Rightarrow\ & b_0 + b_1\,\color{#c00} 2 + b_2\, \color{#c00} 2^2 + b_3\, \color{#c00} 2^3 + \cdots \\[.2em] \equiv\ & b_0 + b_1(\color{#c00}{-1}) + b_2(\color{#c00}{-1})^2 + b_3(\color{#c00}{-1})^3 +\cdots \\[.2em] \equiv\ & b_0 -b_1 + b_2 - b_3 + \cdots \\[.2em] \equiv\ & \color{#c00}{\rm alternating}\ \rm digit\ sum \end{align}$

But on most computers this won't be faster than computing the remainder $\bmod 3\,$ by division.

Bill Dubuque
  • 272,048