void count_rec(struct TreeNode *curr, int *count) { (*count)++; if(NULL != curr){ count_rec(curr->left, count); count_rec(curr->right, count); } }
static void count (tree23_root_t *R, int *A) { A[0] = A[1] = A[2] = 0; if (!R->root) { return; } count_rec (R->root, R->depth, A); }
static void count_rec (tree23_t *T, int depth, int *A) { if (--depth < 0) { A[1]++; A[0]++; if (T->x2 > T->x1) { A[0]++; } } else { A[2]++; count_rec (T->left, depth, A); if (T->x1 < T->x2) { A[0]++; count_rec (T->middle, depth, A); } A[0]++; count_rec (T->right, depth, A); } }
int count_from(int v, int skip, bool clean = true){ usedcnt.resize(V, false); if (clean) { for (int i = 0; i < usedcnt.size(); i++) usedcnt[i] = false; } return count_rec(v, skip); }
int* postorderTraversal(struct TreeNode* root, int* returnSize) { int index; int *nodes; *returnSize = 0; count_rec(root, returnSize); nodes = malloc(sizeof(int) * (*returnSize)); index = 0; se_rec(root, nodes, &index); return nodes; }
char* serialize(struct TreeNode* root) { int count; struct bin_data *data; int index; count = 0; count_rec(root, &count); data = malloc(sizeof(struct bin_data) + count * sizeof(struct node)); index = 0; se_rec(root, data->nodes, &index); return data; }
int count_rec(int v, int skip) { int cnt = 1; usedcnt[v] = true; for (int i = 0; i < edge[v].size(); i++) { int to = edge[v][i]; if(to == skip || usedcnt[to]) continue; cnt += count_rec(to, skip); } return cnt; }
llu count_rec(int* primes, int nb_primes, llu idx, llu current_n, llu current_phi) { llu sum = 0; llu max_p = 1 + MAX_P / current_n; for (llu idxp = idx; idxp < nb_primes; ++idxp) { llu p = primes[idxp]; if (max_p < p) break; llu n = current_n * p, phi = current_phi * (p-1); if (current_n != 1 && (n-1) % (n-phi) == 0) { printf("Found: %llu (%llu)\n", n, phi); sum += n; } sum += count_rec(primes, nb_primes, idxp+1, n, phi); } return sum; }
int main(int argc, char* argv[]) { int nb_primes; int* primes = get_primes(LIM_P, &nb_primes); printf("%llu\n", count_rec(primes, nb_primes, 1, 1, 1)); return 0; }