You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
public static long pow(long a, long b)
{
long k =0;
if ( b == 0 ) return 1;
else if(b % 2 == 0) { // 거듭제곱이 짝수일 때
k = pow(a, b/2);
return (k * k) ;
}
else { // 거듭제곱이 홀수일 때
k = pow(a, (b-1)/2);
return (a * k *k) ;
}
}
지수를 2의 거듭제곱 형태로 표현
O(log지수)
7^21 = ( 7^16 ) * ( 7^4 ) * ( 7 )
==> 21 을 비트로 표현 해보면 10101
The text was updated successfully, but these errors were encountered:
일반적인 방법
분할정복 알고리즘
지수를 2의 거듭제곱 형태로 표현
7^21 = ( 7^16 ) * ( 7^4 ) * ( 7 )
==> 21 을 비트로 표현 해보면 10101
The text was updated successfully, but these errors were encountered: