Sort by

recency

|

4 Discussions

|

  • + 0 comments

    Very happy to have the discussion and the solution of coding on your forum. There should be the people who might looking for the material about and through the help here they able to solve the problem easily. Your essay writing service uk sharing blog updates are quite recommending please continue to share such material.

  • + 2 comments

    Python3 solution

    from fractions import gcd
    
    gcache = {}
    hcache = {}
    
    def G(n):
        if n in gcache: return gcache[n]
        sqrtN = int(n ** .5)
        s = n * (n + 1) // 2
        for g in range(2, sqrtN + 1):
            s -= G(n // g)
            if g != n // g:
                s -= G(g) * (n // g - n // (g + 1))
        if n > 1:
            s -= G(1) * (n // 1 - n // (1 + 1))
        gcache[n] = s
        return gcache[n]
    
    def H(n):
        if n in hcache: return hcache[n]
        s = n
        sqrtN = int(n ** .5)
        for g in range(2, sqrtN + 1):
            s += n // g - H(n // g // g)
        hcache[n] = s
        return s
    
    def S(n):
        s = 0
        sqrtN = int(n ** .5)
        s -= G(sqrtN)
        s += H(n)
        return s - n + 1
    
    n = int(input())
    print(S(n))
    
  • + 1 comment

    Editorial says setters solution is sqrt(n)logn but I don't think it is. Complexity of finding coprime numbers less than m for n is not logn. It's rather 2^k where k is number of distinct prime factors.

    Although my solution is actually sqrt(n)log(sqrt(n)), it is different than setter solution and much more complex which uses mobius function, properties of multiplicative and summatory functions and some other things. I don't use the idea of summing over co-prime numbers. Rather I sum over f(i) and find a way to sum them efficiently. I think setter's solution complexity is a lot more than s/he thinks it is

  • + 2 comments

    Editorial solves in O(N^0.5 * log(N)). I've solved in O(N^0.75) with simple solution than editorial.

No more comments