A-Tree IV long long tree4(long long n) { // write code here long long depth = (log(n) / log(2))+1;//树深度 long long result = 0;//最终结果 long long i=0;//循环下标,从[1,depth-1] long long m=0;//循环下标,仅对depth那层处理 for(i = 1;i <= depth-1;i++)//获得前depth-1层的和 { long long temp=static_cast<long long >(pow(2,i-1)+pow(2,i)-1) %998244353; long long temp1=static_cast<long long >(pow(2,i)- pow(2,i-1))%998244353 ; result+= (i * temp*temp1/2)%998244353; //求和的公式 } for(m =pow(2,depth-1);m<=n;m++)//获得第depth层的和 { result+=(depth*m)%998244353; } return result % 998244353; }

相关推荐

精致的小松鼠人狠话不多:哈哈哈 我每次都差点点一下
点赞 评论 收藏
分享
牛客网
牛客企业服务