Primary cosmic-ray nucleon spectrum in the energy range 40–400 TeV reconstructed from the secondary gamma-ray spectrum in the stratosphere