Realization of near-deterministic arithmetic operations and quantum state engineering