Time and Numeric Utilities
GCD LCM
Greatest common divisor and least common multiple help compare repeating numeric sizes.
GCD LCM
gcd_lcm.cpp
#include <iostream>
#include <numeric>
int main() {
int width = ;
int height = 8;
int common = std::gcd(width, height);
int repeat = std::lcm(width, height);
std::cout << "width=" << width << std::endl;
std::cout << "gcd=" << common << std::endl;
std::cout << "lcm=" << repeat << std::endl;
return 0;
}
#include <iostream>
#include <numeric>
int main() {
int width = ;
int height = 8;
int common = std::gcd(width, height);
int repeat = std::lcm(width, height);
std::cout << "width=" << width << std::endl;
std::cout << "gcd=" << common << std::endl;
std::cout << "lcm=" << repeat << std::endl;
return 0;
}
#include <iostream>
#include <numeric>
int main() {
int width = ;
int height = 8;
int common = std::gcd(width, height);
int repeat = std::lcm(width, height);
std::cout << "width=" << width << std::endl;
std::cout << "gcd=" << common << std::endl;
std::cout << "lcm=" << repeat << std::endl;
return 0;
}
gcd
`std::gcd` finds the largest integer that divides two values evenly.
lcm
`std::lcm` finds the smallest positive integer that is a multiple of both values.