HDU 6950 Mod, Or and Everything

题意

给一个$n(\le 10^{12})$,求$(n \mod 1) | (n \mod 2) | \cdots | (n \mod n)$

思路

虽然不会证,但一眼看上去感觉是个$11\dots11_{(2)}$形式的数,跑个暴力发现是$0$, $0$, $1$, $1$, $3$, $3$, $3$, $3$, $7$, $7$, $7$, $7$, $7$, $7$, $7$, $7$, $\dots$,然后随便一写就过了(xs)

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<bits/stdc++.h>
using namespace std;
#define debug printf("%d %s\n",__LINE__,__FUNCTION__);fflush(stdout)
using ll=long long;using i64=long long;using db=double;
using u32=unsigned int;using u64=unsigned long long;using db=double;
using pii=pair<int,int>;using vi=vector<int>;
using qi=queue<int>;using pqi=priority_queue<int>;using si=set<int>;
#define pb push_back
#define mk make_pair
#define ins insert
#define era erase
#define fi first
#define se second
#define lowbit(x) x&-x
#define ALL(a) a.begin(),a.end()
const int INF=0x3f3f3f3f;
const ll INFLL=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
template<class T>inline bool chkmin(T&a,T b){return b<a?a=b,true:false;}
template<class T>inline bool chkmax(T&a,T b){return a<b?a=b,true:false;}
int _w,_t;FILE* _f;
#define MULTI_CASES

ll n;

void solve(){
scanf("%lld",&n);
if(n<3){
printf("0\n");
return;
}
n--;
while(n!=(lowbit(n))){
n-=lowbit(n);
}
printf("%lld\n",n-1);
}

int main(){
#ifdef MULTI_CASES
_w=scanf("%d",&_t);while(_t--)
#endif
solve();
return 0;
}