Please do try these troubleshooting steps that may help in solving the issue.
- Start by doing a hard reboot, remove the battery and unplug the AC adapter then press and hold the power button for 20 seconds then boot it up.
- If it will shut down, remove the battery and boot it up with just the charger connected and see if it will stay on.
- Next to try if both steps will not work is to try a different AC adapter then see if it will stay on or not.
- If the same problem will persist using a different AC adapter that means there's something else wrong inside the laptop.
- Do reseat the RAM's, remove them all for couple of seconds then put them back in making sure everything is seated properly.
- If these will still not work proceed with cleaning the inside of the laptop, remove the dust off the fans and apply new thermal paste on the CPU.
- Lastly, if all these will not work that means the problem is within the motherboard.