Hint 1
"When he counted them five at a time, he had four left over."
This means that if you divided the total number of sheep by five, you'd have a remainder of four. Think about which numbers produce a remainder of four when you divide them by five and you'll see they all end with a 4 or a 9. The total number of sheep in the farmer's flock must end with 4 or 9.