local function getprimes(x) local primes = {} local allnums = {} for i = 1, x do allnums[i] = true end for i = 2, x do if(allnums[i]) then table.insert(primes, i) local lim = math.floor(x / i) for j = 2, lim do allnums[j * i] = false end end end return primes end local n, p = io.read("*n", "*n") local primes = getprimes(n) if(p == 1) then print(1) elseif(p * 2 <= n) then local ret = n - 1 local lim = math.floor(n / 2) for i = 1, #primes do if(primes[i] ~= p and lim < primes[i]) then ret = ret - 1 break end end print(ret) else local isp = false for i = 1, #primes do if(primes[i] == p) then isp = true print(1) break end end if(not isp) then local ret = n - 1 local lim = math.floor(n / 2) for i = 1, #primes do if(primes[i] ~= p and lim < primes[i]) then ret = ret - 1 break end end print(ret) end end