結果

問題 No.737 PopCount
ユーザー ミドリムシミドリムシ
提出日時 2018-09-28 22:28:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 5,424 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 77,552 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 06:50:22
合計ジャッジ時間 1,369 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 AC 1 ms
5,248 KB
testcase_07 AC 1 ms
5,248 KB
testcase_08 AC 2 ms
5,248 KB
testcase_09 AC 2 ms
5,248 KB
testcase_10 AC 1 ms
5,248 KB
testcase_11 AC 2 ms
5,248 KB
testcase_12 AC 1 ms
5,248 KB
testcase_13 AC 2 ms
5,248 KB
testcase_14 AC 1 ms
5,248 KB
testcase_15 AC 1 ms
5,248 KB
testcase_16 AC 2 ms
5,248 KB
testcase_17 AC 1 ms
5,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

#define int __int128_t
#define long __int128_t

ostream &operator<<(ostream &os, __int128_t value) {
    if (ostream::sentry(os)) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[64];
        char *d = end(buffer);
        do {
            --d;
            *d = "0123456789"[tmp % 10];
            tmp /= 10;
        } while (tmp != 0);
        if (value < 0) {
            --d;
            *d = '-';
        }
        int len = end(buffer) - d;
        if (os.rdbuf()->sputn(d, len) != len) {
            os.setstate(ios_base::badbit);
        }
    }
    return os;
}

istream &operator>>(istream &is, __int128_t &value) {
    string in;
    is >> in;
    value = 0;
    for (const char &c : in) {
        if ('0' <= c && c <= '9') value = 10 * value + (c - '0');
    }
    if (in[0] == '-') value *= -1;
    return is;
}

struct ModInt
{
    int x;
    
    ModInt() : x(0) {}
    
    ModInt(long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p)
    {
        if((x += p.x) >= mod) x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p)
    {
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    
    ModInt &operator*=(const ModInt &p)
    {
        x = (int) (1LL * x * p.x % mod);
        return *this;
    }
    
    ModInt &operator/=(const ModInt &p)
    {
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const { return ModInt(-x); }
    
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    
    bool operator==(const ModInt &p) const { return x == p.x; }
    
    bool operator!=(const ModInt &p) const { return x != p.x; }

    bool operator>(const ModInt &p) const { return x > p.x; }
    
    bool operator<(const ModInt &p) const { return x <  p.x; }

    bool operator>=(const ModInt &p) const { return x >= p.x; }
    
    bool operator<=(const ModInt &p) const { return x <= p.x; }

    ModInt inverse() const
    {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }
    
    friend ostream &operator<<(ostream &os, const ModInt &p)
    {
        return os << p.x;
    }
    
    friend istream &operator>>(istream &is, ModInt &a)
    {
        long x;
        is >> x;
        a = ModInt(x);
        return (is);
    }
    
};

signed main(){
    long long_N;
    cin >> long_N;
    long_N++;
    ModInt N = long_N;
    ModInt ans = 0;
    for(int i = 0; i <= 60; i++){
        ModInt size = (1l << i);
        ModInt length = (long_N / (1l << (i + 1)));
        ModInt side = max(long_N - ((long_N / (1l << (i + 1))) * 2 + 1) * (1l << i), long(0));
        ans += size * size * length * (length + 1) - size * (size + 1) * length / 2 + (length * 2 + 1) * size * side + side * (side - 1) / 2;
    }
    cout << ans << endl;
}
0