[ create a new paste ] login | about

Link: http://codepad.org/xfvhtwXn    [ raw code | output | fork ]

C, pasted on Dec 10:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
typedef unsigned int uint;

uint getMerkleLength(uint leafCount)
{
  uint len = 0, i;
  for (i = leafCount; i > 1; i = (i+1)>>1) {
    len += i;
  }
  return len > 2 ? ++len : 1;
}

void main() {
  uint i;
  for (i = 0; i <= 100; i++) {
    printf("%u: %u\n", i, getMerkleLength(i));
  }
  printf("%u: %u\n", 5000, getMerkleLength(5000));
  printf("%u: %u\n", 99999999, getMerkleLength(99999999));
}


Output:
0: 1
1: 1
2: 1
3: 6
4: 7
5: 11
6: 12
7: 14
8: 15
9: 20
10: 21
11: 23
12: 24
13: 27
14: 28
15: 30
16: 31
17: 37
18: 38
19: 40
20: 41
21: 44
22: 45
23: 47
24: 48
25: 52
26: 53
27: 55
28: 56
29: 59
30: 60
31: 62
32: 63
33: 70
34: 71
35: 73
36: 74
37: 77
38: 78
39: 80
40: 81
41: 85
42: 86
43: 88
44: 89
45: 92
46: 93
47: 95
48: 96
49: 101
50: 102
51: 104
52: 105
53: 108
54: 109
55: 111
56: 112
57: 116
58: 117
59: 119
60: 120
61: 123
62: 124
63: 126
64: 127
65: 135
66: 136
67: 138
68: 139
69: 142
70: 143
71: 145
72: 146
73: 150
74: 151
75: 153
76: 154
77: 157
78: 158
79: 160
80: 161
81: 166
82: 167
83: 169
84: 170
85: 173
86: 174
87: 176
88: 177
89: 181
90: 182
91: 184
92: 185
93: 188
94: 189
95: 191
96: 192
97: 198
98: 199
99: 201
100: 202
5000: 10005
99999999: 200000006


Create a new paste based on this one


Comments: