First we establish a lower bound on the number of colors used. The first student gets $36$ differently colored pencils. The second student then gets one pencil that is the same color as the first students, and then must get $35$ of different colors than the first students. Continuing in this fashion, the $k^{th}$ student gets exactly one pencil matching a color of each of the previous $k-1$ students. Even if these are all different pencils, the $k^{th}$ student still must have $36-(k-1)$ pencils of colors different from the previous students. Thus the total number of colors is at least $36 + 35 + 34 + \dots + 1 = \binom{37}{2}$.
On the other hand this is easily attainable. Take pencils of $\binom{37}{2}$ colors, and label each color with a unique pair of numbers from $\{1,2,\dots,37\}$. Then give a pencil of color $\{a,b\}$ to students $a$ and $b$. This clearly gives each student $36$ pencils and satisfies the criteria, so we are done.