Separation of the Charm and Beauty Production in p–Pb and Pb–Pb Collisions with ALICE