https://acm.hdu.edu.cn/contests/contest_showproblem.php?cid=984&pid=1001

题意:
给出\(n\),求 \(OR_{i=1}^n (n\) \(mod\) \(i)\)

题解:
\(i>n/2\)时,\(n\) \(mod\) \(i\) \(=\) \(n\) \(-\) \(i\)
所以原式 = \(1|2|3|4|5……(n-1)/2\)
因为是连续自然数的或运算,找到最接近的\(2^m-1\)就是答案

#include<cstdio>

int main()
{
    int T;
    long long n,m,b;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld",&n);
        m=n+1>>1;
        m--;
        b=1;
        while(m>=b) b<<=1;
        printf("%lld\n",b-1);
    }
}

相关文章:

  • 2022-01-24
  • 2021-11-05
  • 2021-05-29
  • 2021-12-21
  • 2021-08-23
  • 2021-11-25
  • 2021-09-18
  • 2021-07-18
猜你喜欢
  • 2021-08-09
  • 2021-08-02
  • 2022-01-26
  • 2021-07-15
  • 2022-12-23
  • 2021-09-03
  • 2022-02-14
相关资源
相似解决方案