Ukrainian maths professor Maryna Viazovska won the Fields Medal for her work on sphere packing.

Ukrainian maths professor Maryna Viazovska, who on Tuesday won the top mathematics prize, the Fields Medal, said her life "changed forever" when Russia invaded her home country.

The 37-year-old's parents and sisters were living in Ukraine's capital, Kyiv, when the war began in February.

"I could not think of anything else, including mathematics," she in a video as she received the prize at a ceremony in Helsinki.

Her sisters—along with her young nephew and niece—were evacuated from Kyiv and are now staying with her in Switzerland, where she works at the Ecole Polytechnique Federale de Lausanne.

Viazovska and three other mathematicians received the Fields Medal, dubbed the Nobel prize in maths, in Helsinki after the ceremony was moved from Saint Petersburg to the Finnish capital in response to Moscow's war.

She is only the second woman to receive the award, which is awarded to mathematicians under 40, since it was created in 1936.

The other female laureate, Iran's Maryam Mirzakhani, died of in 2017 just three years after winning the prize.

'Terrible war'

Viazovska was born in 1984 in Kyiv, when Ukraine was part of the Soviet Union.

In Ukraine, she studied at the Taras Shevchenko National University of Kyiv, before earning a masters degree at Germany's University of Kaiserslautern and a Ph.D. at the University of Bonn.

Since 2018, she has been chair of number theory at the Ecole Polytechnique Federale de Lausanne. Her husband Daniil Evtushinsky is a physicist at the Swiss institute.

In the first days of the war, teaching maths to students "helped me to forget about this fear and pain inside myself", she said.

At the ceremony she paid tribute to Yulia Zdanovska, a 21-year-old mathematician who was killed by a Russian missile attack on the Ukrainian city of Kharkiv in March.

"Yulia was a person filled with light and her big dream was teaching mathematics to kids in Ukraine," Viazovska said.

"When die you think, 'What is the point of my work as a teacher if young, talented people are just wasted in this terrible war?'"

13 years to find 'magic formula'

She won the Fields Medal for her work on sphere packing, which has plagued mathematicians for hundreds of years.

It fundamentally involves how to put spheres in a container in the most compact way.

According to legend, it was first a question of how many cannonballs could be packed into a ship, Viazovska said.

After hundreds of years, mathematicians had solved the problem in three dimensions, which involved stacking them in a pyramid, like oranges at a supermarket.

But expanding the theory out into other dimensions—possible in mathematics—had proved elusive.

Viazovska however worked on the problem from 2003 to 2016 and found a "magic formula" that solved the problem in dimensions eight and 24, she said.

"Maryna pulled off something really miraculous here," mathematician Henry Cohn of MIT told the ceremony. "As soon as this paper became available, everyone was astonished by it."

Philippe Moustrou of France's Toulouse University told AFP that it was "not as if she found something that was just waiting to be discovered—she found the extra ingredient".

But Viazovska's thoughts remain with the war—and the hopeful return of a peace she once took for granted.

"The thing I like about Kyiv the most are the green parks, the quiet places and the ancient churches. I understand that now there will be marks of war there and this is a scary thought," she said.

"But Kyiv is one of the eternal cities. One day soon, I hope to return."