1 条题解

  • 0
    @ 2026-7-3 15:11:49

    不大于 nn 且 lowbit⁡\operatorname{lowbit} 值不小于 2t2^t 的数字个数为:

    ⌊n2t⌋\left \lfloor \dfrac{n}{2^t} \right \rfloor

    对 lowbit⁡\operatorname{lowbit} 值差分后累加即可。

    #include <bits/stdc++.h>
    using namespace std;
    inline __int128 read()
    {
    	__int128 x = 0;
    	char c = getchar_unlocked();
    	while (c < '0') c = getchar_unlocked();
    	while (c >= '0')
    	{
    		x = x * 10 + c - '0';
    		c = getchar_unlocked();
    	}
    	return x;
    }
    void write(__int128 x)
    {
    	if (x <= 9)
    	{
    		putchar_unlocked(x + '0');
    		return;
    	}
    	write(x / 10);
    	putchar_unlocked(x % 10 + '0');
    }
    inline void writeline(__int128 x)
    {
    	write(x);
    	putchar_unlocked('\n');
    }
    int main()
    {
    	int T = read();
    	while (T--)
    	{
    		long long n = read();
    		__int128 a = n;
    		for (long long i = 1; (n >> i) >= 1; i++)
    			a += n >> i << (i - 1);
    		writeline(a);
    	}
    	return 0;
    }
    
    • 1

    信息

    ID
    274
    时间
    1000ms
    内存
    512MiB
    难度
    4
    标签
    递交数
    2
    已通过
    2
    上传者