forked from ycshu/110_Fast_Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_gcd2.c
More file actions
45 lines (41 loc) · 627 Bytes
/
4_gcd2.c
File metadata and controls
45 lines (41 loc) · 627 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
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <time.h>
int main() {
int a, b, r, k, N=1 << 25;
time_t t1, t2;
printf("Please input a b : ");
scanf("%d %d", &a, &b);
srand( time(NULL) );
t1 = clock();
for(k=0;k<N;++k){
a = rand();
b = rand();
d = GCD(a,b);
//printf("GCD=%d\n", GCD(a,b));
}
t1 = clock()-t1;
/*
while ( r > 0 ) {
// a = bq + r
// q = a / b;
r = a % b;
// a --> b, b --> r
a = b;
b = r;
printf("(%d,%d)\n", a,b);
}
printf("GCD=%d\n",a);
*/
return 100;
}
int GCD(int a, int b){
int r;
r = a % b;
if(r == 0) {
return b;
}
else {
printf("(%d,%d)\n",b,r);
return GCD(b, r);
}
}