-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcd.cpp
More file actions
36 lines (30 loc) · 767 Bytes
/
gcd.cpp
File metadata and controls
36 lines (30 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using std::cin;
using std::cout;
#include <cstdio>
/* TODO: write me (without looking at the notes if possible) */
size_t gcd(size_t a, size_t b)
{
if (b == 0) {
printf("No remainder!\n");
return a;
}
printf("a:%i b:%i a%b:%i\n", a, b, a % b);
return gcd(b, a % b);
}
/* TODO: write the *extended* GCD algorithm, which returns gcd(a,b), but
* also sets u and v such that ua + vb = gcd(a,b) Warning: this might take a
* little bit of thinking (if you don't just look up the answer online). Save
* it for last. */
int xgcd(int a, int b, int& u, int& v)
{
return 0;
}
int main(void)
{
size_t a,b;
cin >> a >> b;
printf("gcd(%lu,%lu) = %lu\n",a,b,gcd(a,b));
return 0;
}
/* TODO: remind me to setup a schedule for interviews! */