Skip to content

Instantly share code, notes, and snippets.

@masarakki
Last active December 9, 2015 04:58
Show Gist options
  • Save masarakki/4ee182afa9210ae64849 to your computer and use it in GitHub Desktop.
Save masarakki/4ee182afa9210ae64849 to your computer and use it in GitHub Desktop.

n! のケツの0を全部抜いて下から9桁出力しろという問題

通らない

n = gets.to_i
x = 2
3.upto(n) do |i|
  x *= i                                                                        
  x = x.to_s.gsub(/0+$/, '').to_i % 1_000_000_000                           
end
puts x % 1_000_000_000

通る

n = gets.to_i
x = 2
3.upto(n) do |i|
  x *= i                                                                        
  x = x.to_s.gsub(/0+$/, '').to_i % 1_000_000_000_000            
end
puts x % 1_000_000_000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment