Let's say in general you want "n" adjacent squares. Each one needs a top, so that's n toothpicks. Each one needs a bottom, so that's another n toothpicks, and we're up to 2n total. You need one on the far left, and one on the far right, which brings us up to 2n + 2 toothpicks. Now we need to worry about the middle ones. But notice that you don't need n toothpicks for the interior because adjacent squares share. It turns out that you only need n-1. That brings us up to a grand total of 3n + 1 toothpicks, which would be 3001 for n = 1000.
substitute 3 for x in the equation and you get 730 and then substitute 1 for x and you get 28. subtact 28 from 730 and you get 702. then do "b-a" so 3-1 and you get 2. finally, divide 702 by 2 and you get 351.