Can you apply for citizenship if you get a divorce but have two years of permanent residency?

Yes.