import sequtils,math proc getchar_unlocked():char {. importc:"getchar_unlocked",header: "" .} proc scan(): int = while true: let k = getchar_unlocked() if k < '0': break result = 10 * result + k.ord - '0'.ord proc getIsPrimes(n:int) :seq[bool] = # [0...n] O(n loglog n) result = newSeqWith(n+1,true) result[0] = false result[1] = false for i in 2..n.float.sqrt.int : if not result[i]: continue for j in countup(i*2,n,i): result[j] = false proc getPrimes(n:int):seq[int] = # [2,3,5,...n] let isPrimes = getIsPrimes(n) result = @[] for i,p in isPrimes: if p : result &= i let n = scan() let k = scan() if k == 0 : quit "0",0 let primes = getPrimes(k) var ans = 0 for p in primes: let a = 1 + k - p * (n-1) if a <= 0 : break ans += a echo ans