本文介绍了计算算法1 2 4 8图案复杂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要计算该算法的复杂度:
I need to calculate the complexity of this algorithm :
f=1;
x=2;
for(int i=1;i<=n;i*=2)
for(int j=1;j<=i*i;j++)
if(j%i==0)
for(int k=1;k<=j*i;k++)
f=x*f;
我想出图案和内环的总和这为i ^ 2(ⅰ第(i + 1)/ 2)但我不能让这种模式的总和沿系列(1 2 4 8 16 ......)
I figured out the pattern and the summation of the inner loop which is i^2(i(i+1)/2)but I can't get the summation of this pattern along the series of (1 2 4 8 16 ...)
所以,我怎么能找到这个系列的总和?
So, how can I find the summation of this series?
推荐答案
我不打算解决这个你(这看起来像功课)。但这里是一个提示,以简化问题。
I'm not going to solve this for you (this looks like homework). But here is a hint to simplify the problem.
这code:
for(int j=1; j<=i*i; j++)
if(j%i==0)
// ... blah ...
等同于该code:
is equivalent to this code:
for(int j=i; j<=i*i; j += i)
// ... blah ...
这篇关于计算算法1 2 4 8图案复杂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!