题解:CF1275C #define Задача B ...

· · 题解

题解 CF1275C #define Задача B

题目大意

给定递归宏定义:

数组 \texttt{values}[0..4^{25}-1] = A_{25}(0) 展开后的结果。多次查询给定下标的元素值。

解题思路

将下标转换为四进制,从低位到高位:

所有位的和即为答案。

代码实现

#include<bits/stdc++.h>
using namespace std;

int main() {
    int t; cin >> t;
    while (t--) {
        long long n; cin >> n;
        int ans = 0;
        while (n) {
            int d = n & 3;  // 取四进制最低位
            if (d == 1) ans += 1;
            if (d == 2) ans += 3;
            if (d == 3) ans += 4;
            n >>= 2;        // 右移两位,处理下一位
        }
        cout << ans << endl;
    }
    return 0;
}

复杂度

本题解使用了 deepseek-v4-pro 进行润色以保证格式的正确。