calculate using prime factors