The nation’s biggest provider of pharmaceuticals to nursing homes agreed to pay a whopping $49.5 million to resolve two lawsuits.

Omnicare Inc. of Covington, KY, will pay the federal government and 43 state Medicaid programs to settle the claims. The lawsuits alleged the pharmacy illegally switched prescriptions for certain drugs to raise its profits between 2000 and 2005.

The institutional pharmacy also signed a corporate integrity agreement with the Department of Health and Human Services’ Office of Inspector General. Last month Omnicare agreed to pay $40 million to Michigan to settle Medicaid fraud allegations. It was the state’s largest Medicaid fraud recovery in its history.