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
|
define fast_gcd(a, b) {
if (a == b) return a;
if (a > b) return fast_gcd(a - b, b)
return fast_gcd(a, b - a);
}
define void r_reduce(*r[]) {
auto g,s;
if (length(r[]) != 2) sqrt(-1);
if (scale(r[0])) 2^r[0];
if (scale(r[1])) 2^r[1];
if (r[0] >= 0 && r[1] >= 0) g = fast_gcd(r[0], r[1]);
else g = gcd(r[0], r[1]);
s = scale;
scale = 0;
r[0] /= g;
r[1] /= g;
scale = s;
}
define void r_init(*r[], a, b) {
r[0] = a;
r[1] = b;
r_reduce(r[]);
}
define void r_initi(*r[], i, a, b) {
length(r[]);
r[0] = i * b + a;
r[1] = b;
length(r[]);
r_reduce(r[]);
}
length(a[])
r_initi(a[], 5, 63, 94);
|