Pentax know about this problem. It should go on your warranty if you bought second hand or new. I don't think you need a receipt. Contact Pentax.
Do you get black, white or white with pink stripes images before it freezes?
When it freezes and you turn the camera off, do the remaining file count show in the top LCD display?
If you turn it on again, do the battery indicator show in the top LCD display?
Do you have to take out the battery to make the camera work?
All of the above happens to my K20D when it freezes. Some times black images and some times the images are with and/or whit with pink stripes like the one here: