Atcoder Beginner Contest 193 C

2026年9月9日上午正上着班,猫耳FM就弹出了《全职高手》广播剧第四季的正式预告,想着这未来的21周的时间每周都有听觉盛宴,心里高兴极了。
今晚下班后,怀着激动的心情,屁颠屁颠地explore the Atcoder,又遇到了一道基础数学题。
Atcoder Beginner Contest 193 C.Unexpressed
Time Limit: 2 sec / Memory Limit: 1024 MiB
Score : 300 points

Problem Statement
Given is an integer N. How many integers between 1 and N (inclusive) are unrepresentable as a^b, where a and b are integers not less than 2?

Constraints
N is an integer.
1 ≤ N ≤ 10^10

Input
Input is given from Standard Input in the following format:

N

Output
Print the answer.

solution

n = gets.to_i
m = n.pow(0.5).ceil
h = {}
m.downto(2) do |i|
  x = Math.log(n, i).floor
  if x >= 2
    (2..x).each do |j|
      h[i ** j] = 1
    end
  end
end
puts n - h.length

AC啦,欢迎方锐大大加入兴欣战队!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容