Modified to calculate for sequences 1 to 1000 only.