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; }

相关推荐

皮格吉:不,有的厂子面试无手撕,可以试试。都是一边学一边面。哪有真正准备好的时候,别放弃
无实习如何秋招上岸
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务