Блог пользователя lowest_contribution

Автор lowest_contribution, история, 16 месяцев назад, По-английски

A set of tiles are numbered 1-N, In one step you can remove all tiles with a square number,and than rename all the tiles,starting from 1. This is the question,

and what I found is is formula ceil((sqrt(N)-1)*2)

I tried many values still unsuccessfull of proving or disproving anything about this question,

Please Help me prove or disprove this cool formula or trick I would rather say.

  • Проголосовать: нравится
  • +16
  • Проголосовать: не нравится

»
16 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

hmm.. interesting

»
16 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What does the formula calculate?

»
16 месяцев назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +1 Проголосовать: не нравится

lets find all intervals $$$[l_i, r_i]$$$ that for all numbers from i-th interval, we need do $$$i$$$ steps. we know that $$$l_0 r_0 = {0, 0}$$$, now we need to find next segment. its easy to understand that $$$l_{i+1} = r_i + 1$$$ so we need find only $$$r_{i+1}$$$. lets say we have X tiles, we know that we will remove exactly $$$\sqrt{X}$$$ tiles, so $$$r_{i+1} - \sqrt{r_{i+1}} = r_i$$$ here we get a formula that can be solved by the discriminant.
my solution
I wrote the code and got the following segments:
$$$0$$$ from $$$1$$$ to $$$1$$$
$$$1$$$ from $$$2$$$ to $$$2$$$
$$$2$$$ from $$$3$$$ to $$$4$$$
$$$3$$$ from $$$5$$$ to $$$6$$$
$$$4$$$ from $$$7$$$ to $$$9$$$
$$$5$$$ from $$$10$$$ to $$$12$$$
We can see that

$$$r_i = \frac{i + 2}{2} * ((i + 2) - \frac{i + 2}{2}) = \frac{(i + 2)^2}{4}$$$

knowing all the above, I can get the expression that you described

»
16 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится
#include <bits/stdc++.h>
using namespace std;

int main() {
    const int N = 1e9;
    vector<int> dp(N + 1);
    dp[1] = 0;
    for(int i = 2; i <= N; i++){
        int removed = sqrt(i);
        dp[i] = dp[i - removed] + 1;
        assert(dp[i] == ceil((sqrtl(i) - 1) * 2));
    }
}

This works on my PC, so I guess proof by AC? I asked chatgpt to prove by induction and I think it's right, but I won't bother reading the proof carefully:

https://chatgpt.com/share/688b4d1c-84f8-8011-b237-2fd33527475b

»
16 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

This is only an approximation;

Assume we start with $$$n$$$.

$$$(\sqrt n - 1)^2 = n - 2\sqrt n + 1 \lt n - \sqrt n$$$ (the numbers left after the first step), so we remove the squares of the numbers $$$1\ldots\sqrt n$$$ and $$$1\ldots\sqrt n - 1$$$ (kind of).

So in two steps, we reach from $$$n = (\sqrt n)^2$$$ to $$$(\sqrt n - 1)^2$$$, then in another two $$$(\sqrt n - 2)^2$$$, etc.

And this gives $$$2\sqrt n$$$ steps.