main, primitive root calculations