Algorithm to calculate the number of 1s for a range of numbers in binary

前端 未结 6 1939
再見小時候
再見小時候 2021-01-30 00:39

So I just got back for the ACM Programing competition and did pretty well but there was one problem that not one team got.

The Problem.

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-30 00:59

    I think it's a problem in Discrete mathematics,
    assuming LOW is 0,
    otherwise we can insert a function for summing numbers below LOW,
    from numbers shown i understand the longest number will consist up to 60 binary digit at most

    alg(HIGH,k)
    
    l=len(HIGH)
    sum=0;
    
    for(i=0;i


    all the numbers appear
    non is listed twice
    numbers_with_i_above is trivial
    canreach with numbers up to 60 is easy
    len is it length of a binary represention

提交回复
热议问题