Restricting program memory
avd.reduct.ru
avd.reduct.ru
It's a bit of a weird exercise, you'd generally just calculate the maximum space used by the algorithm, maybe account for stack frame size if recursion is used.
TL;DR: 1M is too small to do it.
PIC 16F84A - 1K Program Memory, 68 bytes Data Memory, 64 bytes EEPROM