def prime(n) r = [] a = Array.new(n+1,true) for i in 2..[36,n].min if a[i] r << i for j in 1..n/i a[i*j] = false end end end for i in [36,n].min..n if a[i] r << i end end r end x = gets.to_i p = prime(x) ans = 0 b = 0 e = p.size-1 while b <= e if p[b]*p[e] > x ans += p[e] e -= 1 else temp = 1 while temp <= x temp *= p[b] end if temp/p[b]+p[e] < p[b]*p[e] ans += p[b]*p[e] e -= 1 else ans += temp/p[b] end b += 1 end end p ans