For each positive integer \(p\), let \(b(p)\) denote the unique positive integer \(k\) such that \(|k-\sqrt{p}| < \frac{1}{2}\). For example, \(b(6) = 2\) and \(b(23) = 5\). If \(S = \sum_{p=1}^{2007} b(p),\) find the remainder when \(S\) is divided by 1000.

(第二十五届AIME1 2007 第11题)