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

Автор feecIe6418, 5 лет назад, По-английски
A Tutorial
A Code
B Hint 1
B Hint 2
B Hint 3
B Tutorial
B Code (Python)
C Hint 1
C Hint 2
C Tutorial
C Code
D Hint
D Tutorial
D Code (Python)
E1 Hint
E1 Tutorial
E1 Code
E2 Hint
E2 Tutorial
E2 Code
Разбор задач Codeforces Round 729 (Div. 2)
  • Проголосовать: нравится
  • +184
  • Проголосовать: не нравится

»
5 лет назад, скрыть # |
 
Проголосовать: нравится -23 Проголосовать: не нравится

Great problems

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +24 Проголосовать: не нравится

Good stuff, I liked C a lot, it made me think of LCM in a new way

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +10 Проголосовать: не нравится

    can you please elaborate your thought about LCM..

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

      yes plz how u thought of lcm i thought of 3 first then thought for 6 then 12 and come up with factorial approach but it hasn't worked.

      • »
        »
        »
        »
        5 лет назад, скрыть # ^ |
        Rev. 4  
        Проголосовать: нравится +8 Проголосовать: не нравится

        I'll try to explain.

        $$$n \leq 1e16$$$, so just starting a loop and trying to find an answer for each $$$i (1 \leq i \leq n)$$$ is a bad idea. This is why we need to "group" the answers. It is important to understand that the answers cannot be great. Because if $$$f(i) = x$$$, it means that i has divisors $$$2, 3, 4 \dots x - 1$$$, so $$$i \geq lcm (2, 3, 4 \dots x - 1)$$$

        Let's try to figure out what $$$⌊n / lcm (1,2, \dots, i) ⌋$$$ means. This is the number of elements that are divisible by $$$2, 3, 4 \dots i$$$, so we have not counted the answer for them yet. Thus, based on the editiorial "The number of ks such that $$$f (k) = i$$$ is $$$⌊n / lcm (1,2, \dots, i — 1) ⌋ — ⌊n / lcm (1,2, \dots, i)⌋$$$" It means that $$$⌊n / lcm (1,2, ..., i — 1) ⌋$$$ is the number of elements that have "reached" us. And $$$⌊n / lcm (1,2, ..., i) ⌋$$$ is the number of elements for which the answer is greater than $$$i$$$. Thus, subtracting one from the other, we get the number of elements for which the answer is equal to $$$i$$$. And of course, sorry for my bad English, I tried my best.

        My C++ solution:

        121264752

    • »
      »
      »
      5 лет назад, скрыть # ^ |
      Rev. 2  
      Проголосовать: нравится +2 Проголосовать: не нравится

      to know how many numbers in range 1 to n are divisable by all numbers from 1 to i it equals to n / lcm(1,2,3,..,i) for example :- if n = 15 and you want to know how many number divisable by 1, 2, 3 and 4 floor(15 / lcm(1,2,3,4)) = 1 there is just one number divisable by 1, 2, 3, and 4 and this number is 12.

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Thanks for the editorial

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +24 Проголосовать: не нравится

Mathforces!

»
5 лет назад, скрыть # |
 
Проголосовать: нравится -73 Проголосовать: не нравится

This one requires a lot more math, but it's not friendly to younger participants. And, this is an algorithm competition, not a math competition.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +22 Проголосовать: не нравится

Great Round, Great problems. Statements were short and crisp problem "C" is my personal favourite. Looking forward to see more such rounds. Thank you!!!

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

Although I didn't participate, I also think the problems especially C and D are wonderful!

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

When I was solving B, for some reason I typed "a^x" as "a*x" and spent almost all round to understand why extended euclidian algorithm doesn't work. Moral of the story: Don't tunnel vision, do your math.

Great round!

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +15 Проголосовать: не нравится

I spent over an hour on b since I put (n % (a ^ k))%b == 0 instead of (n — (a ^ k))%b == 0.

Nonetheless the problems were good, and I enjoyed the round

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +58 Проголосовать: не нравится

I think B is harder to think than D.

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

Imagine C is harder to think than D...

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

Can someone explain the second paragraph of $$$B$$$ tutorial?

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    Let us assume n is present in the set. n can be represented as x*a^k + y*b, where x,k,y are whole numbers. Now n%b = (x*a^k + y*b)%b = (x*a^k)%b = x%b * (a^k)%b. x can be any of the previous values in the set, used to generate n. Thus we can assume x = (x')*(a^k') + y*b and x%b = (x')%b * (a^k')%b. Eventually we can see that x%b will be of type a^k where k will be a whole number. Hence we can write n%b = (a^k)%b, given n is present in the set.

»
5 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится +28 Проголосовать: не нравится

I had a slightly different approach for problem C. So I will explain my solution and thinking process.

Initially I was not able to solve the problem. Then I remembered one thing that factorial of even small numbers is very large (like $$$50!$$$). So, this gave me direction to think that $$$f(n)$$$ cannot be very large. So I ran a test to see that when we multiply prime numbers up to $$$50$$$, it will exceed $$$10^{16}$$$.

I still had no clue how to solve this problem. Then I randomly wrote a number in prime factorization form. I saw that $$$f(n)$$$ can only be some power of only a single prime i.e. $$$f(n) = p^k$$$ where $$$p$$$ is some prime and $$$k$$$ is its power. I was able to prove this.

Now, I knew that $$$f(n)$$$ can only be some power of prime up to $$$50$$$. So, now if $$$f(n)=p^k$$$, then $$$n$$$ must have exactly $$$p^{k-1}$$$ in its prime factorization form because otherwise $$$p^{k-1}$$$ will be $$$f(n)$$$. Now, I had to think what else should $$$n$$$ must have in its prime factorization form. I observed that for some other prime $$$q$$$ its power $$$m$$$ must be such that $$$q^{m+1} \gt p^k$$$ because otherwise $$$q^{m+1}$$$ can be answer. Then I found a number $$$D$$$ satisfying the above requirements. Now, the number of multiples of $$$D$$$ minus the number of multiples of $$$D*p$$$ would give the numbers for which $$$f(n) = p^k$$$. Then I would just add contribution to answer. Note that we have to handle a corner case i.e. when $$$D$$$ exceeds $$$n$$$, then we don't take any contribution from $$$p^k$$$.

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

Any idea why this solution to B gives TLE? Is it some silly mistake? Cause I've pretty much followed the editorial.

void solve(int testcase) {
    int n, a, b; cin >> n >> a >> b;
 
    if (a == 1) {
        cout << ((n - 1) % b == 0 ? "Yes\n": "No\n");
        return;
    }
 
    int m=1;
    bool res=false;
    while (m <= n) {
        if (m % b == n % b) {
            res = true;
            break;
        }
        m *= a;
    }
 
    cout << (res ? "Yes\n": "No\n");
}
»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone analysis the time complexity of problem C for me pls?

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

Can someone please guide me through the equivalence of both formulas in C?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится -30 Проголосовать: не нравится

math math math math math maTh MaTH MATH MATH MATH MATH MATH MATH MATH AAAAAAAAAAAAAAAAAAAA!!!!1!!!11!!!

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +27 Проголосовать: не нравится

These format of spoilers hurt my eye really bad, can you make it like this ? It will look much better.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +39 Проголосовать: не нравится

Really a great contest! Kudos!

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +20 Проголосовать: не нравится

»
5 лет назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

Nice contest.
- Team Atcoder Fan, 2021

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

in the C Tutorial : "Since f(n)= i means lcm(1,2,...,i−1) ≤n " why? I don't understand this, can you explain it to me?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

why chinese people think,that math problems are more interesting than algorithmic or data structure?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

Can someone help me understand how they thought of this DP (and it's states) in problem D?

The current editorial focuses more on implementation, less on the idea.

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

    watch galen colin video.

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +19 Проголосовать: не нравится

    When you have these expected value problems and you have to compute the total value (or expected value) of all sums, you can generally compute the total contribution of each term and add it separately.

    I think this can somewhat be seen by putting all the subsets of sums with the # of times they get counted vertically. When you add all of them up, you just get one equation in the $$$n$$$ variables (for whatever $$$n$$$ is, here it's the number of terms that start with $$$+$$$). The coefficient of each variable here is the number of times it's counted across all subsets -- which is the same as its independent contribution. Then, you can proceed as above.

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

Look at my code for B, it's very funny compared to the original solution, but still my code passed all the tests. Here is the link: https://mirror.codeforces.com/contest/1542/submission/121210576

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

What are $$$p1$$$ and $$$q1$$$ in E1 editorial? And what do you mean by enumerating $$$p1$$$ and $$$q1$$$? feecIe6418

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

Hi, I don't understand the editorial of problem B. Can someone please explain it to me?

Thanks

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    Here is my approach — Every element of the set can be expressed in the form $$${a^p + qb}$$$ where p and q are whole numbers. You can try writing the elements of the set in a tabular form to see it for yourself, intuitively. $$$1,1+b,1+2b,1+3b...$$$
    $$$a,a+b,a+2b,a+3b...$$$ $$$a^2,a^2+b,a^2+2b,a^2+3b...$$$

    We want to check if n is expressible in this form. To do this, iterate through p from 0 to any large enough value. For each value of p, check if $$$n = a^p + qb$$$, that is, ($$$n - a^p$$$)%b == 0. If this is true, the answer is YES. The loop terminates when $$$a^p$$$ becomes greater than n itself.

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

Does anyone have a different solution for E1?

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +55 Проголосовать: не нравится

froggyzhang had given a solution for e2 by using generating functions which i think is much easier than the official tutorial(which is also great!). Unluckily, it's in Chinese. And if anyone want to read it you can find it here.

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

Is there any recursive approach to solve D

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

In B, is it true that if $$$n$$$ is equal to some power of $$$a$$$ then $$$n$$$ belongs to the set?

I had the following condition in my code:

if( n % a == 0) {
    cout << "Yes\n";
    continue;
}

and for some reason this gives a wrong answer. My reasoning was the following. If $$$1$$$ and $$$1 \cdot a$$$ are in the set then $$$1 \cdot a \cdot a$$$ must also be in the set and other powers e.g. $$$1 \cdot a \cdot a \cdot a$$$ as well. So if $$$a$$$ divides $$$n$$$ i.e. $$$n \pmod a == 0$$$ then $$$n$$$ should be in the set. Am I missing something trivial ????

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

Can someone explain in better/different words what the states in the DP for D actually represent? The editorial is not at all clear to me.

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    For each number x, to determine whether it's in the final set or not, we only need to consider those numbers that are smaller than x. Because those larger ones will always be popped after x is popped. If there are more than one x, we assume the one that appears first is smaller.

    So, for each number x, define f[i][j] represent: after considering the ith operation, how many subsequences are there satisfies that there are j numbers in the set are smaller than x. (Remember to ignore the operation for the number x).

    Then do the dynamic programming as the tutorial shows.

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

      "If there are more than one x, we assume the one that appears first is smaller." Can you explain why so?

      • »
        »
        »
        »
        5 лет назад, скрыть # ^ |
         
        Проголосовать: нравится +8 Проголосовать: не нравится

        Actually, this is just an assumption to prevent some number being counted twice.

        For example, the whole sequence is +1 +1 -.

        After processing the whole sequence +1 +1 -, the final set is 1.

        When we count the first +1, we will not count the sequence +1 +1 -, cause the first +1 is smaller, according to the assumption. The 1 in the final set is the second +1, we'll count this one when processing the second +1.

        If you don't set the rule for equal elements, +1 +1 — will be counted for both +1, which is not what we want.

  • »
    »
    5 лет назад, скрыть # ^ |
     
    Проголосовать: нравится +22 Проголосовать: не нравится

    You can have a look here and the parent comment, I tried to explain it with a picture:

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

What a nice math contest!(C is really nice)

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

Brilliant Problems!! Thanks for such a nice contest.

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Could anyone explain why I got a time limit exceed in problem B test 2?

Thank you so much.

#include <iostream>
using namespace std;

int main() {
    int tcs, tc, n, a, b, i;
    bool f;
    cin >> tcs;
    for (tc = 0; tc < tcs; tc++) {
        cin >> n >> a >> b; 
        if (a == 1) cout << (n % b == 1 ? "Yes" : "No") << endl;
        else {
            i = 1; f = false;
            while (i <= n) {
                if ((n - i) % b == 0) {f = true; break;}
                i *= a;
            }
            cout << (f ? "Yes" : "No") << endl;
        }
    }
    return 0;
}
»
5 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Someone please explain solution of D. I am unable to comprehend the tutorial solution.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Can anyone explain me div 2 D solution

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

when coming up with dp solutions of taskE1 would you write the initial statements first(for(int i=1;i<=n*(n-1)/2;i++)s[0][i]=1;) or figure it out after the recursive statements? Because I had a hard time writing the initial statements,not knowing how many elements in the array should I initialize(Like why is s[0][0]=1 not needed). Please share some tips! and sorry for my bad English

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +21 Проголосовать: не нравится

I'M THE ONLY ONE FST ON D!!!!!!!!!!!!! :(

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +47 Проголосовать: не нравится

Let me introduce froggyzhang's idea of problem E in English. You can find the original edition here(in Chinese).

I recommend you read the first and second paragraph of the official tutorial of E2 and the official tutorial of E1 before reading the following part of this article.

Assume $$$p_{i+1}=a$$$ and $$$q_{i+1}=b$$$, $$$a,b$$$ are their rank in their permutations.

So $$$inv(p) \gt inv(q)\Leftrightarrow inv(p[i+2,\dots n])-inv(q[i+2\dots n]\ge b-a+1$$$. So we just want to find the number of the pairs of permutations $$$p,q$$$ of length $$$n-i-1$$$ and $$$inv(p)-inv(q)\ge b-a$$$.

Precalculate $$$f(i,j)$$$ the number of the pairs of permutations $$$p,q$$$ and $$$inv(p)-inv(q)=j$$$. You can insert the numbers to the permutation from small to big and you can do it in $$$O(n^4)$$$ or $$$O(n^5)$$$ by using brute force(which is also mentioned in the official tutorial of E2).

You will find inserting number $$$i$$$'s generating function is as follow:

$$$ \sum_{j=0}^{i-1}x^j\sum_{j=0}^{i-1}x^{-j}=\frac{x^i-1}{x-1}\cdot\frac{x^{-i}-1}{x^{-1}-1}=\frac{x^{i+1}+x^{-i+1}-2x}{(x-1)^2} $$$

About the above part we can write it in to DP functions($$$a\to b$$$ means we add the value of $$$a$$$ to $$$b$$$).

$$$ f[i-1][j]\to f[i][j+i+1]\\ f[i-1][j]\to f[i][j-i+1]\\ -2f[i-1][j]\to f[i][j+1]\\ $$$

And $$$\frac{1}{(x-1)^2}$$$ means we want to roll back twice. Just think what do you do when you $$$\times (x-1)^2$$$. So we can calculate $$$f$$$ in $$$O(n^3)$$$(both time and memory). We can only keep two layers of transition to optimize the memory to $$$O(n^2)$$$. And we can calculate suffix sum and the answer of the same prefix in $$$O(n^2)$$$.

You can read froggyzhang's code in his blog. You can find other details of coding in his code if you need.

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

In the implementation of problem D, why is the additional if (i!=t) : f[i][j]=(f[i][j]+f[i-1][j])%mod there at the end of innermost for loop? Isn't the case where we skip the ith element already considered in each case?

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

Can anyone explain problem D. I didn't understand the solution in editorial.

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

This is my code for Div2 D

Spoiler

Someone please provide me any small testcase for debugging.

»
5 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Hey I don't know why I am wrong answer on test 2 of Problem B. This is my submission: https://mirror.codeforces.com/contest/1542/submission/121246560 Can you tell me what I am wrong. Thanks you

»
5 лет назад, скрыть # |
Rev. 4  
Проголосовать: нравится 0 Проголосовать: не нравится

Edit: Understood my mistake.

Can someone tell me what's wrong in my logic for B: I observed a pattern for f(n) over numbers. Till every 6th number f(n) is 2 3 2 3 2, and for every 6th number, if the divisor upon dividing the number by 6 if odd then f(n) is 4 otherwise 5. So if n = 12, f(n) = 2 + 3 + 2 + 3 + 2 + 4 + 2 + 3 + 2 + 3 + 2 + 5 = 33. This logic is not working for the pretest 1 (10^16). Can anyone tell what's wrong in this?

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

in tutorial for C, why ∑i>1i(⌊n/lcm(1,2,...,i−1)⌋−⌊n/lcm(1,2,...,i)⌋) is equal to ∑i≥1⌊n/lcm(1,2,...,i)⌋+n?

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

Sorry,I'm not sure abount Problem D.If there are multiple smallest elements and then we execute an erasing operation,what will happen?Will we erase all the smallest elements or just erase one of them?

»
4 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Problem $$$E1$$$ is very nice. I have an alternative solution, which to me at least makes more sense.

In a lot of these problems where we have $$$p \lt q$$$ for some permutation/array $$$p, q$$$, we can break up $$$p, q$$$ into some interval $$$[1, \dots i]$$$ in which $$$p_j = q_j \forall j \in [1, i]$$$, $$$p_{i + 1} \lt q_{i + 1}$$$ and then an arbitrary permutation from $$$i + 2$$$ onwards. Perhaps my notation is a bit pedantic; maybe an example will help:

$$$p = 1 3 4 5 2$$$

$$$q = 1 3 2 4 5$$$

In this case, $$$p$$$ and $$$q$$$ share a common prefix of length $$$2$$$. Then, after that, we have that $$$4 \gt 2$$$, so we know that $$$p \gt q$$$. $$$[5, 2]$$$ and $$$[2, 5]$$$ can be respectively remapped to a new permutation ($$$[2, 5] \to [1, 2]$$$).

Okay, so let's assume that $$$p, q$$$ share some prefix of length $$$len$$$. Then, we know that $$$p_{len + 1} \gt q_{len + 1}$$$, so we can iterate over pairs $$$p_{len + 1} \lt q_{len + 1}$$$, which serve as a sort of distinguisher. If we let $$$dp[n][k]$$$ be the number of permutations of length $$$n$$$ with $$$k$$$ inversions, then we see that $$$ans[inv]$$$ — the number of pairs $$$p, q, p \lt q$$$ such that $$$\text{inv} (p) \gt \text{inv} (q)$$$ — can be written as:

$$$ans[inv] = ans[inv] + dp[N - len - 1][inv + q_{ind + 1} - p_{ind + 1}] \cdot \frac{N!}{(N - len)!}$$$

It remains to find $$$dp[n][k]$$$. The editorial has a good explanation on that, so I omit that detail.

Also needs some optimization since this is $$$\mathcal{O}(N^5)$$$. Can be optimizes if we iterate over $$$q_{ind + 1} - p_{ind + 1}$$$ instead.

Cheers!

EDIT: SAME IDEA CAN SOLVE E2 LET'S GOOOO: 145998673 First 2700 problem solved w/o editorial!!

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

In problem C,

I think there is an interesting pattern to observe...

Look...

For all Odd numbers,

x will always be 2.

For even numbers,

Please correct me If I am wrong...

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

    This is wrong. For example, $$$f(60)=7$$$.

  • »
    »
    4 года назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    I solved this by observing such patterns (probably bad idea, but this all I can come up)

    We can see 4 is alternating with 5, but the after the forth 4 is not 5 but 7 (at 60)

    Still, 4 occurs every 6 path minus every 12 path (which can be 5, or 7, or anyelse)

    Let's write g(x): times occurrences of a number x in length n.

    g(4) = n/6 - n/12

    Let's check g(x) for some other x.

    g(2) : something like n/2
    g(3) = n/2 - n/6
    g(4) = n/6 - n/12
    g(5) = n/12 - n/60
    g(6) = 0
    g(7) = n/60 - n/420
    g(8) = n/420 - n/840
    

    We can see a pattern here, but why g(6) = 0? also what's up with g(8)?

    Turns out g(x) = 0 for all x which has more than one prime factor. (in this case 6 = 2*3)

    And g(8)'s pattern is different because the pattern actually concerns with its prime factor (in this case 8's sole prime factor is 2).

»
3 года назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

For C :- — We need to min positive integer for each number 1 , 2 ... N which doesn't divide it.

-  We can do grouping of numbers ( of x ).


   lets take an example first 
   -> N / 2 = number of elements divisible by 2
   -> N / 3 = number of elements divisible by 3

   -> N / 6 = number of elements divisible by 6  
            = number of elements divisible by 2 and 3
            = number of elements divisible by lcm(1,2,3) ie lcm(1,2,..i) elements                 

  N / lcm(1..i) -> numbers in N which are divisible by first i elements
  N / lcm(1...i-1) -> numbers in N which are divisible by first (i - 1) elements
  so  N / lcm(i...i) - N / lcm(1.. i-1)  = no of elements not divible by  I.


 we can do it for all numbers till 42
 since lcm of first 42 elements > 1e16.