An approximation algorithm for cofactoring-based synthesis