-
-
Save hority/6217606 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
require 'rubygems' | |
require 'twitter' | |
class Integer | |
def prime? | |
n = self.abs() | |
return true if n == 2 | |
return false if n == 1 || n & 1 == 0 | |
d = n-1 | |
d >>= 1 while d & 1 == 0 | |
20.times do | |
a = rand(n-2) + 1 | |
t = d | |
y = ModMath.pow(a,t,n) | |
while t != n-1 && y != 1 && y != n-1 | |
y = (y * y) % n | |
t <<= 1 | |
end | |
return false if y != n-1 && t & 1 == 0 | |
end | |
return true | |
end | |
end | |
module ModMath | |
def ModMath.pow(base, power, mod) | |
result = 1 | |
while power > 0 | |
result = (result * base) % mod if power & 1 == 1 | |
base = (base * base) % mod | |
power >>= 1; | |
end | |
result | |
end | |
end | |
Twitter.configure do |config| | |
config.consumer_key = "" | |
config.consumer_secret = "" | |
config.oauth_token = "" | |
config.oauth_token_secret = "" | |
end | |
input = gets.to_i | |
sosu = input.prime? | |
if sosu == true then | |
Twitter.update "\n / ) | |
/ ( | |
/ ヽ | |
◜◔。◔◝ | |
| | #{input}は素数〜!! | |
| ⊃ ⊃ | |
└-⊃~⊃" | |
else Twitter.update "\n / ) | |
/ ( | |
/ ヽ | |
◜◔。◔◝ | |
| | #{input}は素数じゃない〜!! | |
| ⊃ ⊃ | |
└-⊃~⊃" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment