The Characterization of Graphs Whose Sandpile Group has Fixed Number of Generators