Odd Divisors
求([A, B])中所有数的最大奇因子的和
奇数显然是本身,偶数直接递归处理即可
#include <iostream>
using namespace std;
#define ll long long
#define ri register int
#define rep(io, st, ed) for(ri io = st; io <= ed; io ++)
#define drep(io, ed, st) for(ri io = ed; io >= st; io --)
#define gc getchar
inline int read() {
int p = 0, w = 1; char c = gc();
while(c > '9' || c < '0') { if(c == '-') w = -1; c = gc(); }
while(c >= '0' && c <= '9') p = p * 10 + c - '0', c = gc();
return p * w;
}
ll solve(int n) {
if(n <= 1) return n;
int m = (n + 1) / 2;
return 1ll * m * m + solve(n / 2);
}
int main() {
int T = read();
while(T --) {
int A = read(), B = read();
printf("%lld
", solve(B) - solve(A - 1));
}
return 0;
}