結果

問題 No.1181 Product Sum for All Subsets
ユーザー ミドリムシミドリムシ
提出日時 2022-03-28 08:46:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 3,288 bytes
コンパイル時間 1,647 ms
コンパイル使用メモリ 164,096 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 15:56:01
合計ジャッジ時間 2,827 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
constexpr lint mod = 1e9 + 7;
#define all(x) begin(x), end(x)
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzll(x))
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define rep2(i, l, r) for(int i = int(l); i < int(r); i++)
#define repr(i, n) for(int i = int(n) - 1; i >= 0; i--)
#define repr2(i, l, r) for(int i = int(r) - 1; i >= int(l); i--)
constexpr int inf9 = 1e9; constexpr lint inf18 = 1e18;
inline void Yes(bool condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void array_output(itr start, itr goal){ for(auto i = start; i != goal; i++) cout << (i == start ? "" : " ") << (*i); cout << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(b) return gcd(b, a % b); else return a; }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b){ if(b < a){ a = b; return 1; } return 0; }
inline int has(lint i, int j){ return (i >> j) & 1; }
int dy[4] = {1, 0, -1, 0}; int dx[4] = {0, 1, 0, -1};
bool is_inside(lint y, lint x, lint H, lint W){ return (0 <= y && y < H && 0 <= x && x < W); }

struct io_init {
    io_init() {
        cin.tie(nullptr); cout.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }
} io_init;

struct Modint{
    lint x;
    
    Modint(): x(0) {}
    Modint(lint x): x(x >= 0 || x % mod == 0 ? x % mod : mod - (-x) % mod) {}
    
    Modint operator +(Modint a){ return Modint(*this) += a; }
    Modint operator -(Modint a){ return Modint(*this) -= a; }
    Modint operator *(Modint a){ return Modint(*this) *= a; }
    Modint operator /(Modint a){ return Modint(*this) /= a; }
    
    Modint operator -(){ return Modint(0) - Modint(*this); }
    
    Modint& operator +=(Modint a){
        x += a.x;
        if(x >= mod) x -= mod;
        return *this;
    }
    
    Modint& operator -=(Modint a){
        if(x < a.x) x += mod;
        x -= a.x;
        return *this;
    }
    
    Modint& operator *=(Modint a){
        x = x * a.x % mod;
        return *this;
    }
    
    Modint& operator /=(Modint a){
        (*this) *= a.inv();
        return *this;
    }
    
    Modint inv(){
        return pow(mod - 2);
    }
    
    Modint pow(lint exp){
        Modint ans(1), powed = (*this);
        while(exp){
            if(exp % 2) ans *= powed;
            powed *= powed;
            exp /= 2;
        }
        return ans;
    }
    
    bool operator ==(Modint a){ return x == a.x; }
    bool operator !=(Modint a){ return x != a.x; }
};

ostream& operator <<(ostream& os, Modint a){
    os << a.x;
    return os;
}

istream &operator >>(istream &is, Modint& a){
    lint x;
    is >> x;
    a = Modint(x);
    return is;
}

Modint get_triangle(lint n){
    return Modint(n) * (n + 1) / 2;
}

int main(){
    int n;
    lint k;
    cin >> n >> k;
    auto p = get_triangle(k + 1) - 1;
    auto q = get_triangle(k);
    cout << p.pow(n) - q.pow(n) << endl;
}
0