라벨이 C++인 게시물 표시

[Math] GCD & LCM

GCD(Greatest Common Divisor) & LCM(Least Common Multiple) 1. Find GCD of two number Method 1: use basic Euclidean algorithm. GCD(a, b) = GCD(b%a, a) Method 2: use extended Euclidean algorithm. GCD(a, b) = ax + by Let values of x and y calculated by the recursive call be x 1 and y 1 x = y 1 - ⌊b/a⌋ * x 1 y = x 1 2. Find LCM of two number LCM(a, b) * GCD(a, b) = a * b 3. Reference http://www.geeksforgeeks.org/mathematical-algorithms/#gcd

i++ vs ++i in C and C++

Prefer ++i over i++. In C language, there is no difference between ++i and i++. In C++, ++i has performance gain rather than i++ because of object copy. In detail, refer followings https://stackoverflow.com/questions/24853/what-is-the-difference-between-i-and-i https://stackoverflow.com/questions/24886/is-there-a-performance-difference-between-i-and-i-in-c