An Efficient Algorithm for Determining the Number of 5G Slices