Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- /*
- Problem statement
- Given that a and b are 2 integers such tat 13 gcd(a,b) = lcm(a, b)
- and a + b = 2016, what are the values of a and b?
- */
- // copied from other flie, great
- // euclidian algorithm
- unsigned gcd(unsigned u, unsigned v)
- {
- while (v != 0)
- {
- unsigned r = u % v;
- u = v;
- v = r;
- }
- return u;
- }
- // ab = (a, b)[a, b]
- // [a, b] = ab / (a, b)
- unsigned lcm(unsigned u, unsigned v)
- {
- return (u / gcd(u, v)) * v;
- }
- int main()
- {
- for (int a = 1; a <= 2015; a++)
- {
- int b = 2016 - a;
- if (13 * gcd(a, b) == lcm(a, b))
- {
- cout << a << " " << b << endl;
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement