Question 1209438
<font color=black size=3>
Answer: <font color=red>89 sheep</font>


Explanation


This problem is practically identical to the locker problem
<a href="https://math.stackexchange.com/questions/2017047/the-locker-problem-why-squares">https://math.stackexchange.com/questions/2017047/the-locker-problem-why-squares</a>
and also the light switch problem
<a href="https://math.hmc.edu/funfacts/toggling-light-switches/">https://math.hmc.edu/funfacts/toggling-light-switches/</a>
They are basically the same idea just with a different coat of paint so to speak.


Any non-perfect square has an even number of factors. This leads to an even number of swaps.
For instance sheep number 6 goes free since it has four swaps (due to the four factors 1,2,3,6)
This sheep starts outside and ends outside. 


Any perfect square has an odd number of factors, so those sheep numbers have an odd number of swaps.
Those unfortunate sheep start outside the mouth and end up eaten. 


There are 9 perfect squares between 1 and 98 since 9^2 = 81 is the largest perfect square of the list.
9 sheep are eaten and the other 98-9 = <font color=red>89</font> sheep survive.


--------------------------------------------------------------------------


Another approach


Let's look at a smaller flock say of 10 sheep.
The monster places all of them into its mouth.
1, 2, 3, 4, 5, 6, 7, 8, 9, 10


Erase the even numbers
1, 3, 5, 7, 9


Then go through the multiples of 3 between 1 and 10. 
If you find 3, 6, or 9 in that previous list, then erase it. 
Otherwise introduce it back into the list.
We go from
1, 3, 5, 7, 9
to
1, 5, 6, 7


Now go through the multiples of 4. 
If you find 4 or 8 in the previous list above then erase it. Otherwise add it in.
We go from 
1, 5, 6, 7
to
1, 4, 5, 6, 7, 8


Keep this process going until reaching 10.



Here's the full process
<table border = "1" cellpadding = "5"><tr><td>Round</td><td>Sheep In Mouth</td></tr><tr><td>1</td><td>1, 2, 3, 4, 5, 6, 7, 8, 9, 10</td></tr><tr><td>2</td><td>1, 3, 5, 7, 9</td></tr><tr><td>3</td><td>1, 5, 6, 7</td></tr><tr><td>4</td><td>1, 4, 5, 6, 7, 8</td></tr><tr><td>5</td><td>1, 4, 6, 7, 8, 10</td></tr><tr><td>6</td><td>1, 4, 7, 8, 10</td></tr><tr><td>7</td><td>1, 4, 8, 10</td></tr><tr><td>8</td><td>1, 4, 10</td></tr><tr><td>9</td><td>1, 4, 9, 10</td></tr><tr><td>10</td><td>1, 4, 9</td></tr></table>
We see that the perfect squares remain.
These sheep are eaten. The others go free.


Applying this idea to numbers 1 through 98 will show that 1, 4, 9, 16, 25, 36, 49, 64, 81 are eaten.
There are 9 of those values so 98-9 = <font color=red>89</font> sheep go free.
It might help to make a 10 by 10 grid of numbers from 1 to 100. Cross off 99 and 100 since the list ends with 98.
</font>