Chimps have "replayed" an ancient fable, a team says in Plos One journal.
In Aesop's 2,000-year-old tale, a crow uses stones to raise the water level in a pitcher to reach the liquid so as to quench its thirst.
But when given a similar set up, chimps were able to attain an out-of-reach, floating peanut by spitting water taken from a dispenser into a vertical tube.
One hungry chimp went even further by urinating into the vessel to get hold of the prized snack.
"He was spitting water into the tube, then got frustrated," explained lead researcher Daniel Hanus from the Max Planck Institute for Evolutionary Anthropology in Leipzig, Germany.
"So he started peeing and then he realised: 'Wait a minute, if I move in that direction, that fills up the tube'."
The chimp's unusual method proved successful, the scientist said. The fact that the peanut was urine-sodden did not deter the animal from eating it, he added.
The study was carried out with gorillas and chimpanzees.
The primates were presented with a vertical glass tube, which was secured to a cage so it could not be moved or broken. At the bottom was a peanut, floating on a small amount of water.
They were also given access to a water dispenser.
The idea was that the animals would take water from the dispenser in their mouths, and then spit it into the tube to raise the water level.
It would take several visits back and forth between the dispenser and tube to gather enough water to get to the peanut.
The team found that none of the five gorillas was able to complete the task.
Chimps however were more successful. Out of 43 chimps, based in the Ngamba Island Chimpanzee Sanctuary, in Uganda, and Germany's Leipzig Zoo, 14 worked out that they needed to take the water in their mouths and spit it into the tube, and seven did this enough times to successfully obtain a peanut.
Dr Hanus said the study highlighted the chimps' ability to solve problems.
He explained: "You cannot explain it by trial-and-error learning. They weren't just spitting water around the room and some fell in by accident.
"Instead, they were standing in front of the problem, trying to work out the solution - at first by trying to use their fingers, or trying to break it.
"But some, then went to the drinker and got the mouthful of water and came back and spat it directly into the tube, and a few did it enough times to get the peanut."
He added: "I think it is quite impressive - I call it insightful behaviour."
The urinating chimp, he said, was an interesting case.
The animal had initially solved the problem using the standard spitting technique, but when tested again, he was struggling to direct the water into the tube.
The urine did the trick, said Dr Hanus.
He said: "He seemed like he understood. He was like: 'That's cool, this helps me'."
The team also repeated the study with children of varying ages.
Dr Hanus said: "Whenever we talked to people about this task, they'd say: 'Well, this is a demanding task, it is tricky - I don't know if I could solve that'.
"So we decided to test four, six and eight-year-olds."
This time, the subjects were given a watering can to fill up the tube rather than rely on a water dispenser and a refined spitting technique.
The researchers found that the four-year-olds were outperformed by the chimps: only two out 24 younger children could solve the problem.
Six-year-olds did better, with 10 out of the 24 managing to work out they needed to use the water. And eight-years-olds did the best, 14 children - 58% - completed the task.
Dr Hanus said: "Even the older children found it hard. It was interesting and impressive to see how difficult it was for them."
This research follows a similar study carried out with orangutans in 2007. They were very good at solving this problem: five out of the five primates tested could successfully complete the task.
The team said the difference between the three primate species was striking - although they plan to test the gorillas again using a slightly different set-up.
Birds too have been able to carry out this task.
A paper published in 2009 revealed that rooks were highly successful at working out a solution to this problem.
With a slightly different experiment design, where the birds had to drop stones into the water, and a peanut exchanged for a floating maggot, the team found that all four of the rooks tested could complete the task.