Accumulated Earnings Credit Question

Can someone tell me the formula to calculate the accumulated earnings credit? From Becker, to me it seems like they're saying: 250,000 - [BEG E&P - CORP. NEEDS]. But I also saw another explanation that said it was the greater of: 250,000 - BEG E&P or BEG E&P - CORP. NEEDS - CAPITAL GAINS NET OF TAX Can someone please clarify? Thanks!