zoukankan      html  css  js  c++  java
  • 最大奇约数求和

     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <bitset>
     6 #include <vector>
     7 #include <queue>
     8 #include <stack>
     9 #include <cmath>
    10 #include <list>
    11 #include <set>
    12 #include <map>
    13 #define rep(i,a,b) for(int i = a;i <= b;++ i)
    14 #define per(i,a,b) for(int i = a;i >= b;-- i)
    15 #define mem(a,b) memset((a),(b),sizeof((a)))
    16 #define FIN freopen("in.txt","r",stdin)
    17 #define FOUT freopen("out.txt","w",stdout)
    18 #define IO ios_base::sync_with_stdio(0),cin.tie(0)
    19 #define mid ((l+r)>>1)
    20 #define ls (id<<1)
    21 #define rs ((id<<1)|1)
    22 #define INF 0x3f3f3f3f
    23 using namespace std;
    24 typedef long long LL;
    25 typedef pair<int, int> PIR;
    26 const int N = 1e5+5;
    27 
    28 LL n;
    29 int main()
    30 {IO;
    31 //    FIN;
    32 //    FOUT;
    33     while(cin >> n){
    34         LL ans = 0;
    35         while(n){
    36             if(n&1)    ans += (1+n)*(n/2+1)/2;
    37             else ans += n*(n/2)/2;
    38             n >>= 1;
    39         }
    40         cout << ans << endl;
    41     }
    42     return 0;
    43 }
    View Code
  • 相关阅读:
    hdu 2203 亲和串
    hdu 3999 The order of a Tree
    poj 2299 Ultra-QuickSort
    hdu 1908 Double Queue
    hdu 1556 Color the ball
    hdu 4288 Coder
    hdu 5265 pog loves szh II
    hdu 5058 So easy
    T103763 【模板】矩阵乘法
    T103492 【模板】点双连通分量
  • 原文地址:https://www.cnblogs.com/NWUACM/p/6480285.html
Copyright © 2011-2022 走看看