blob: 42c39970c56d21a9a7663e47b8e27a2389e1ff18 (
plain) (
blame)
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
|
// a +1 loop whose bound is len of the fixed array: the check is gone, the sum is not
fn acc(fixed []int f) {
int n = len(f), i = 0, s = 0;
for (; i < n; i += 1) f[i] = i + 1;
for (i = 0; i < n; i++) s = s + f[i];
return s;
}
o3 fn acc3(fixed []int f) {
int n = len(f), i = 0, s = 0;
for (; i < n; i++) f[i] = i + 1;
for (i = 0; i < n; i++) s += f[i];
return s;
}
o3 fn small(fixed []int f) {
int n = len(f), c = 0, i, j;
for (i = 2; i < n; i++) f[i] = 1;
for (i = 2; i * i < n; i++)
if (f[i]) for (j = i * i; j < n; j += i) f[j] = 0;
for (i = 2; i < n; i++) c += f[i];
return c;
}
fn main() {
fixed []int f = new(fixed []int, 10);
fixed []int g = new(fixed []int, 20);
put_n(acc(f)); put_c(32); put_n(acc3(f)); put_c(32); put_n(small(g)); put_c(10);
free(d*f); free(d*g);
return 0;
}
|