High-efficiency quantum-nondemolition single-photon-number-resolving detector