帮我分析一下这个二分取幂的原理,这个算法可以求出2^x,2的x次幂 c++的long long func(int x){\x05if(x==0) return 1;\x05long long res;\x05res=func(x/2);\x05res*=res;\x05if(x%2==1)\x05res*=2;\x05return (res%1234567);}

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 16:18:34
帮我分析一下这个二分取幂的原理,这个算法可以求出2^x,2的x次幂 c++的long long func(int x){\x05if(x==0) return 1;\x05long long res;\x05res=func(x/2);\x05res*=res;\x05if(x%2==1)\x05res*=2;\x05return (res%1234567);}

帮我分析一下这个二分取幂的原理,这个算法可以求出2^x,2的x次幂 c++的long long func(int x){\x05if(x==0) return 1;\x05long long res;\x05res=func(x/2);\x05res*=res;\x05if(x%2==1)\x05res*=2;\x05return (res%1234567);}
帮我分析一下这个二分取幂的原理,这个算法可以求出2^x,2的x次幂 c++的
long long func(int x)
{
\x05if(x==0) return 1;
\x05long long res;
\x05res=func(x/2);
\x05res*=res;
\x05if(x%2==1)
\x05res*=2;
\x05return (res%1234567);
}

帮我分析一下这个二分取幂的原理,这个算法可以求出2^x,2的x次幂 c++的long long func(int x){\x05if(x==0) return 1;\x05long long res;\x05res=func(x/2);\x05res*=res;\x05if(x%2==1)\x05res*=2;\x05return (res%1234567);}
当x为偶数2k时,2^x=(2^k))^2,
当x为奇数2k+1时,2^x=2*(2^k)^2