标签:com main 题解 code ble long 深度 tps 数加
题目大意 求每个点对的lca深度的和
以每一层分析,得出通式
由于1e9的数据范围要化简表达式得到O(能过)
瞎搞后就是2^(2n+2)-(4n+2)*2^n-2
code:
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1e9+7;
long long n;
long long ksm(long long aa,long long b) {
long long ans=1;
while(b) {
if(b&1) ans=((ans%mod)*(aa%mod))%mod,ans%=mod;
aa*=1LL*aa;
aa%=mod;
b>>=1;
}
return ans;
}
int main() {
cin>>n;
cout<<(ksm(2,2*n+2)-((4*n%mod+2)*ksm(2,n))%mod-2+mod)%mod;//处理负数加膜数取膜
return 0;
}
标签:com main 题解 code ble long 深度 tps 数加
原文地址:https://www.cnblogs.com/skkyk/p/11663523.html