Let the total length of pencil = L cm
Then, black part = L/8
∴ Remaining part = L - L/8 = 7L/ 8
and White part = (7L/8)/2 = 7L/8
∴ Remaining part = L - (L/8 + 7L/16) = 7L/16
∴ length of blue part = 7L/16
According to the question,
7L/16 = 31/2
⇒ 7L/16 = 7/2
∴ L =8