帮我分析一下这个二分取幂的原理,这个算法可以求出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/07/07 01:34:28
帮我分析一下这个二分取幂的原理,这个算法可以求出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){cݳO;ڞ͛dGÓ/|cՓ]=@Ӟlz>it rMyOv/}i. #gk5($kky9y `"4/Y#3DB:43M@S((O$P_Z Ҷ`F0-[4U#[[CMTX uMR>M= 2`RF daHp TEFȚXFf$+q۳MߦtQ\f`Eچ0eFZ`qF6yvPeIy

帮我分析一下这个二分取幂的原理,这个算法可以求出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