import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class No51 { public static void main(String[] args) throws IOException{ //やる気の問題 String[] text = readStr(); int W = Integer.parseInt(text[0]) , D = Integer.parseInt(text[1]); while(D > 1){ W = W - Math.floorDiv(W, D * D); D--; } System.out.println(W); } public static String[] readStr() throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); ArrayList list = new ArrayList<>(); do { list.add(br.readLine()); }while(br.ready()); br.close(); String[] text = new String[list.size()]; list.toArray(text); return text; } }