Sort by

recency

|

7 Discussions

|

  • + 0 comments

    Using your math skills can be a very interesting and even rewarding experience. For example, platforms such as offer a large selection of opportunities where analysis and calculations can become your assistant. Mathematics helps not only in strategic planning, but also in understanding various mechanics and algorithms. Knowing probability, statistics, and even basic mathematical formulas can give you an edge by helping you make informed decisions. When you understand how different elements work, such as the odds of certain events or outcomes, you become more confident in your choices and actions. In addition, many online platforms offer analysis tools that can help you better understand patterns and trends. . Using mathematical approaches can turn your online entertainment into an exciting intellectual activity. So don't be afraid to use your mathematical skills - it can greatly increase your enjoyment of games and leisure.

  • + 0 comments

    Another dumb Python3 solution, but at least I did it by myself.

    import math
    from collections import Counter
    
    def main():
        a, b = map(int, input().split())
        llen, lsum = muls(a,b)
        rlen,rsum = xors(a,b)
        lmul = 10**(len(str(b))+1)
        print(lsum*lmul*rlen + llen*rsum)
    
    
    def muls_naive(a,b):
        s = set(x*y for x in range(1,a+1) for y in range(1,b+1))
        return len(s), sum(s)
                 
    def xors_naive(a,b):
        s = set(x^y for x in range(1,a+1) for y in range(1,b+1))
        return len(s), sum(s)
    
    def xors(a,b):
        if b<31:
            s = set(x^y for x in range(1,a+1) for y in range(1,b+1))
            return len(s), sum(s)
        bm  = (b+1)//32
        s = set(x^y for x in range(1, a+1) for y in range(bm*32, b+1))
        rlen, rsum =  len(s), sum(s)
        rsum += bm*32*(bm*32-1)//2 
        rlen += bm*32
        if a == 1:
            rlen -= 1
            rsum -= 1
        return rlen, rsum
    
    
    def parts(lo, hi, limit):
        lst = Counter({1:-1})
        for k in range(lo, hi+1): # build all incl/excl combos
            lst1 = Counter()
            if any(k%i==0 for i in lst if i>1): continue
            for (i,v) in lst.items():
                k1 = i*k//math.gcd(i,k)
                if k1 <= limit: lst1[k1] -= v
            lst.update(lst1)
        del lst[1]
        return lst
                
    def mulsum(lo, hi, k): # multiples of k in range lo..hi
        ilo = (lo-1)//k+ 1
        ihi = hi//k
        lret = ihi - ilo +1
        sret = k * (ilo + ihi) * (lret) // 2
        return lret, sret
    
    def muls_parts(a, b):
        # if b < 50: return muls_naive(a,b)
        lret, sret = b, b*(b+1)//2
        for k in range(2, a+1):
            lo, hi = (k-1)*b + 1, k*b
            pp = parts(k, a, hi)
            for (p,v) in pp.items():
                lp, sp = mulsum(lo, hi, p)
                # print(f'section {k}: [{lo},{hi}]  part ({p},{v}) -> {lp}, {sp}')
                lret += v*lp; sret += v*sp
        return lret, sret
    
    muls = muls_parts
    # xors = xors_naive
    
    main()
    
  • + 1 comment

    Python3 solution

    def gcd(x, y):
        while y != 0:
            (x, y) = (y, x % y)
        return x
    
    def sumProdRef(A, B):
        all = set()
        for x in range(1, A + 1):
            for y in range(1, B + 1):
                all.add(x * y)
        return sum(all), len(all)
    
    def sumXorRef(A, B):
        all = set()
        for x in range(1, A + 1):
            for y in range(1, B + 1):
                all.add(x ^ y)
        return sum(all), len(all)
    
    def sumProdOneDivider(divider, limit):
        count = limit // divider
        return divider * (count + 1) * count // 2, count
    
    def get(result, x, limit):
        items = result.items()[:]
        if x not in result:
            result[x] = 0
        result[x] += 1
        if result[x] == 0:
            del result[x]
        for d, v in items:
            dx = d * x
            if dx > limit:
                continue
            if dx not in result:
                result[dx] = 0
            result[dx] -= v
            if result[dx] == 0:
                del result[dx]
        return result
    
    def getInterval(start, finish, limit):
        result = {}
        for x in range(start, finish):
            items = list(result.items())[:]
            isdiv = False
            for d in range(start, x):
                if x % d == 0:
                    isdiv = True
                    break
            if isdiv:
                continue
            result[x] = 1
            for d, v in items:
                dx = d * x // gcd(d, x)
                if dx > limit:
                    continue
                if dx not in result:
                    result[dx] = 0
                result[dx] -= v
                if result[dx] == 0:
                    del result[dx]
        return result
    
    def sumProd(A, B):
        all = set()
        s = 0
        l = 0
        for x in range(A, 0, -1):
            process = getInterval(x, A + 1, A * B)
            for d, v in process.items():
                sx0, lx0 = sumProdOneDivider(d, B * (x - 1))
                sx1, lx1 = sumProdOneDivider(d, B * x)
                s += v * (sx1 - sx0)
                l += v * (lx1 - lx0)
        return s, l
    
    def sumXor(A, B):
        if B < 100:
            return sumXorRef(A, B)
        b = B - 100
        s = b * (b + 1) // 2
        l = b + 1
        all = set()
        for x in range(1, A + 1):
            for y in range(b + 1, B + 1):
                xy = x ^ y
                if xy <= b:
                    continue
                all.add(xy)
        s += sum(all)
        l += len(all)
        return s, l
            
    A, B = map(int, input().split())
    prod, nprod = sumProd(A, B)
    xor, nxor = sumXor(A, B)
    result = prod * nxor * pow(10, len("%d" % B) + 1) + nprod * xor
    print(result)
    
  • + 1 comment

    how should I optimize my code, it is able to pass only two test cases and in rest time exceeded

    # Enter your code here. Read input from STDIN. Print output to STDOUT
    import math
    inp = list(map(int,input().split())) 
    x=inp[0]
    y=inp[1]
    length = len(str(y))+1
    total = 0
    ls1 = set()
    ls2 = set()
    for i in range(1,x+1):
        for j in range(1,y+1):
            ls1.add((i*j*pow(10,length)))
            ls2.add(int(str(i^j).zfill(length)))
    for i in ls1:
        for j in ls2:
            total = total+(i+j)
    print(total)
    
  • + 0 comments

    I write the code and code works in eclipse. And it works under 1 sec its like minisec but when i test code here i get timeout error. Is this a bug. Code is not long or not efficient by anyway its a normal clear code. Help pls. Edit: Just realize that my code is actualy not efficient for long numbers :D. So no problem in hackerRank. I just be overdefensive coz i work on code long time. And thought it is a perfect code. But its just working code not efficient. :D. I know why they called this expert level now.