公式

B - Base 2 解説 by en_translator


Use a for statement to find the answer just as described in the problem statement. As in the sample code below, the implementation will be concise if you use the bit shift operator. Note that a signed 64-bit integer (like long long in C++) is not suitable for this problem, because it can represent only up to \(2^{63}-1\). (Instead, use an unsigned 64-bit integer or a bigint.)

Sample code (C++)

#include<bits/stdc++.h>

using namespace std;

using ull = unsigned long long;

int main() {
    ull ans = 0;
    for (int i = 0; i < 64; i++) {
        ull a;
        cin >> a;
        ans += a << i;
    }
    cout << ans << endl;
}

Sample code (Python) :

a = list(map(int, input().split()))
ans = 0
for i in range(64):
    ans += a[i] << i
print(ans)

投稿日時:
最終更新: