zoukankan      html  css  js  c++  java
  • 水题

    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;
    }
    
  • 相关阅读:
    js 创建对象
    js的面向对象
    js的JSON
    js 标准对象
    js generator
    js 闭包
    js sort
    js filter关键字
    [转载] 自定义标签,jsp调用java类
    JSTL标签常用
  • 原文地址:https://www.cnblogs.com/reverymoon/p/13932484.html
Copyright © 2011-2022 走看看