Skip to content

Instantly share code, notes, and snippets.

@hority
Forked from sasamijp/sosutwit.rb
Last active December 21, 2015 00:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hority/6217606 to your computer and use it in GitHub Desktop.
Save hority/6217606 to your computer and use it in GitHub Desktop.
# -*- 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