Method to extract the primary cosmic ray spectrum from very high energy gamma-ray data and its application to SNR RX J1713.7-3946