On each day of its life a scroboscopus square its number of legs. For example, if a scroboscopus has 2 legs on it first day of life, it would have 4 legs on its second day, and 16 legs on its third day. Tom bought some newborn scroboscopi. Some had 2 legs, some had 3 legs, and some had 5 legs. The total leg count was 58 legs. The next day the leg count was 164. The following day, the leg count was 1976. How many scroboscopi did Tom buy?