Exemple #1
0
struct node *copy_branch(struct tree *dst, struct node *src)
{
    switch (src->token) {
    case token_x:
        return new_var(dst, token_x);
    case token_y:
        return new_var(dst, token_y);
    case token_z:
        return new_var(dst, token_z);
    case token_a:
        return new_var(dst, token_a);
    case token_num:
        return new_num(dst, src->value);
    case token_pow:
        return new_pow(dst, copy_branch(dst, src->left), src->value);
    case token_mul:
        return new_node(dst, copy_branch(dst, src->left), token_mul, copy_branch(dst, src->right));
    case token_add:
        return new_node(dst, copy_branch(dst, src->left), token_add, copy_branch(dst, src->right));
    case token_sub:
        return new_node(dst, copy_branch(dst, src->left), token_sub, copy_branch(dst, src->right));
    case token_neg:
        return new_node(dst, 0, token_neg, copy_branch(dst, src->right));
    case token_sqrt:
        return new_node(dst, 0, token_sqrt, copy_branch(dst, src->right));
    case token_err:
        return 0;
    default:
        error::set_num(error::unknown_token);
        return 0;
    }
}
Exemple #2
0
void asm_simplifications_prep_rec( OpWithSeq *op ) {
    if ( op->id == OpWithSeq::current_id )
        return;
    op->id = OpWithSeq::current_id;
    
    if ( op->type == STRING_pow_NUM and op->children[1]->type == OpWithSeq::NUMBER ) {
        double v = op->children[1]->val();
        int n = int( 2 * v );
        if ( n == 2 * v and ( n & 1 ) ) { // ^ n/2
            OpWithSeq *ch = new_pow( op->children[0], 2 * v );
            //
            op->type = STRING_sqrt_NUM;
            op->children[0]->remove_parent( op );
            op->children[1]->remove_parent( op );
            op->children.clear();
            op->add_child( ch );
        }
    }
    
    // recursivity
    for(unsigned i=0;i<op->children.size();++i)
        asm_simplifications_prep_rec( op->children[i] );
}
Exemple #3
0
int main()
{
    int i, r, num_cases;
    int pow[NUM_DIGITS] = {2,3};    // 32
    long long delta, n;

    init_powtab();
    delta = 4; n = 5;
    for (r = 2; r <= 20; r++) {
        while (!digits_ok(pow, r)) {
            n += delta;
            new_pow(n, pow);
        }
        ntab[r] = n;
        delta *= 5;
    }

    scanf("%d\n", &num_cases);
    for (i = 1; i <= num_cases; i++) {
        scanf("%d", &r);
        printf(FORMAT, i, r, ntab[r]);
    }
    return 0;
}