写一下二叉树 推一下公式就出来了, 注意取模时的输出形式
#include <bits/stdc++.h> #define mem(a, b) memset(a, b, sizeof(a)) using namespace std; typedef long long LL; const int maxn = 1e6+5, INF = 0x7fffffff, MOD = 1e9+7; LL n, k; LL qp(LL a, LL b) { LL res = 1; while(b) { if(b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } int main() { while(cin>> n >> k) { if(n == 0) { cout<< 0 <<endl; return 0; } n %= MOD; cout<< ((qp(2, k+1) * n % MOD - (qp(2, k) - 1 + MOD) % MOD) + MOD) % MOD <<endl; } return 0; } //348612312017571993 87570063840727716