Skip to content

Instantly share code, notes, and snippets.

@magurofly
Last active June 23, 2020 02:29
Show Gist options
  • Save magurofly/a1027d29a640043189a15ee10ceb73a5 to your computer and use it in GitHub Desktop.
Save magurofly/a1027d29a640043189a15ee10ceb73a5 to your computer and use it in GitHub Desktop.
Check if the number is Sophie Germain prime, prime number, or not
#See also: ABC084 D - 2017-like Number
require "set"
n = gets.to_i
require "prime"
n_is_prime= false
n21_is_prime = false
Prime.each(n*2+1) { |prime| # これはひどい
n_is_prime = true if prime == n
n21_is_prime = true if prime == n*2+1
}
if n_is_prime
if n21_is_prime
puts "Sophie Germain"
else
puts "Prime"
end
else
puts "Composite"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment