-
Notifications
You must be signed in to change notification settings - Fork 6
/
lcm1.c
54 lines (41 loc) · 971 Bytes
/
lcm1.c
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <stdio.h>
#include <stdlib.h>
void vassume(int b){}
void vtrace1(int a, int b, int x, int y, int u, int v){}
void vtrace2(int a, int b, int x, int y, int u, int v){}
void vtrace3(int a, int b, int x, int y, int u, int v){}
int mainQ(int a, int b){
vassume(a >= 1);
vassume(b >= 1);
int x,y,u,v;
x=a;
y=b;
u=b;
v=0;
while(1) {
//assert(x*u + y*v == a*b);
//%%%traces: int a, int b, int x, int y, int u, int v
vtrace1(a, b, x, y, u, v);
if (!(x!=y)) break;
while (1){
//%%%traces: int a, int b, int x, int y, int u, int v
vtrace2(a, b, x, y, u, v);
if(!(x>y)) break;
x=x-y;
v=v+u;
}
while (1){
vtrace3(a, b, x, y, u, v);
//%%%traces: int a, int b, int x, int y, int u, int v
if(!(x<y)) break;
y=y-x;
u=u+v;
}
}
//x==gcd(a,b)
return u+v; ; //lcm
}
int main(int argc, char **argv){
mainQ(atoi(argv[1]), atoi(argv[2]));
return 0;
}