evolution of advanced math ability
Just to avoid misunderstandings
Just to avoid potential misunderstandings on your side, I wanted to talk about the saying that

human [are] evolved from primates


Humans are primates, so did our common ancestor with other primates.
Our ancestors are different from modern day primates. Chimps for example (which are great apes, like us) are not our ancestor more than we are their ancestors. We just share a common ancestor (who lived about 13 millions years ago).

Spandrel, exaptation and panselectionist arguments
Your are doing two mistakes. 1) The mistake of the spandrel (named after the title of the famous and old paper Gould and Lewontin (1979)) and the exaptation and 2) a panselectionist mistake.
1. Spandrel and exaptation
Spandrel

In evolutionary biology, a spandrel is a phenotypic characteristic that is a byproduct of the evolution of some other characteristic, rather than a direct product of adaptive selection

See also What is the “Spandrels” debate about?.
Exaptation

Exaptation [..] describe[s] a shift in the function of a trait during evolution.

While the existence of a spandrel in an evolutionary process does not necessarily cause the existence of an exaptation, but I will not go into these semantics details for simplicity.
Consider for example the two following wrong statements.


Birds have feathers to fly. It is impossible that birds evolved feather to fly because early feathers would have served no purpose to flight.


Bird feather actually probably first evolved for temperature regulation. Once this was done feathers were an exaptation for early flying tools.


Humans have nose to wear glasses. It is impossible that nose would have evolved because there was no glasses before


Noses evolved for another purpose and happen to be an exaptation for wearing glasses.


Humans have a big brain for advanced mathematical skills. It is impossible that humans evolved such big brains as such mathematical skills were useless in a time where we did not invent/discover much of the most basic math concept yet.


Humans evolved a big brain, mainly for social reasons incl. social hunting and social communication and probably because it was/is under sexual selection (see wikipedia &gt; evolution of human intelligence). It just happen that logical reasoning, abstract thinking and other cognitive skills are an exaptation for advanced math skills.
2. Panselectionist view of evolution
I just want to highlight that there is much more to evolution than just mutations and natural selection. Not every trait has been selected for (otherwise we would not have any genetic disease).
On this subject, you might want to have a look at the paragraph Did you say Natural Selection? of this answer to Why don't mammals have more than 4 limbs? and to Why do some bad traits evolve, and good ones don't?