change to write n first then compute factorization