I have a Lumia 520. It was doing a restart every minute, also opening any application would trigger the restart as well! I tried to format it to make work again, but without success.
What do I do? Is it some hardware problem I cannot repair?
The first things to go about is to perform a Hard Reset. Although you mentioned formatting your phone, I can't surely imply that you have performed a hard reset. I recommend you hard reset your phone. To do this:
Press and hold the Volume down and Power buttons at the same time until you feel a vibration (about 10-15 seconds). When you feel the vibration, immediately press and hold the Volume down button until you see a large exclamation mark.
If that doesn't help, the only option is that you take your phone the nearest Microsoft Care Center(former Nokia Care center). Explain them your problem, it could most likely be a hardware problem. I'm sure they will be able to help you out.
Update: I did not read the comments, I see you have already tried Hard Resetting, please ignore the hard reset part.
Try updating your handset, a critical update is available for all Lumia phones that addresses the random reboot issues!