This file contains hidden or 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
# coding: utf-8 | |
# Box=Muller 法に基づいて, 平均 0.0 分散 1.0 の正規乱数を発生させる | |
def box_muller | |
x = Random.rand(1.0) | |
y = Random.rand(1.0) | |
z = Math.sqrt(-2.0 * Math.log(x)) * Math.cos(2.0*Math::PI*y) | |
w = Math.sqrt(-2.0 * Math.log(x)) * Math.sin(2.0*Math::PI*y) # not use |
This file contains hidden or 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
require 'prime' | |
# 無限降下法 (descent) | |
# | |
# input: (x, y, k, p) s.t. kp = x^2 + x^2 | |
# output: (x, y, k, p) s.t. p = x^2 + x^2, k = 1 | |
def descent(x, y, k, p) | |
if k == 1 |
This file contains hidden or 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
# 無限降下法 (descent) | |
# | |
# input: (x, y, k, p) s.t. kp = x^2 + x^2 | |
# output: (x, y, k, p) s.t. p = x^2 + x^2, k = 1 | |
def descent(x, y, k, p) | |
if k == 1 | |
return [x, y, 1, p] | |
else |
This file contains hidden or 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
# The Gaussian periods modulo 65537 | |
p = 65537 | |
g = 3 (primitive root modulo 65537) | |
Z/pZ := [1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 46073, 7145, 21435, 64305, 61841, 54449, 32273, 31282, 28309, 19390, 58170, 43436, 64771, 63239, 58643, 44855, 3491, 10473, 31419, 28720, 20623, 61869, 54533, 32525, 32038, 30577, 26194, 13045, 39135, 51868, 24530, 8053, 24159, 6940, 20820, 62460, 56306, 37844, 47995, 12911, 38733, 50662, 20912, 62736, 57134, 40328, 55447, 35267, 40264, 55255, 34691, 38536, 50071, 19139, 57417, 41177, 57994, 42908, 63187, 58487, 44387, 2087, 6261, 18783, 56349, 37973, 48382, 14072, 42216, 61111, 52259, 25703, 11572, 34716, 38611, 50296, 19814, 59442, 47252, 10682, 32046, 30601, 26266, 13261, 39783, 53812, 30362, 25549, 11110, 33330, 34453, 37822, 47929, 12713, 38139, 48880, 15566, 46698, 9020, 27060, 15643, 46929, 9713, 29139, 21880, 103, 309, 927, 2781, 8343, 25029, 9550, 28650, 20413, 61239, 52643, 26855, 15028, 45084, 4178, 12534, 37602, 47269, 10733, 32199, 31060, 27643, 17392, 5 |
This file contains hidden or 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
# coding: utf-8 | |
# ガウス周期の大きさ(複素数)を数値的に計算して,正負の判定を行う | |
require 'set' | |
require 'prime' | |
require 'complex' | |
# 原始根を計算する | |
# prime |
This file has been truncated, but you can view the full file.
This file contains hidden or 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
# The Gaussian periods modulo 65537 | |
p = 65537 | |
g = 3 (primitive root modulo 65537) | |
# 1 dim'l Gaussian periods: | |
(65536, 1) = [1]+[3]+[9]+[27]+[81]+[243]+[729]+[2187]+[6561]+[19683]+[59049]+[46073]+[7145]+[21435]+[64305]+[61841]+[54449]+[32273]+[31282]+[28309]+[19390]+[58170]+[43436]+[64771]+[63239]+[58643]+[44855]+[3491]+[10473]+[31419]+[28720]+[20623]+[61869]+[54533]+[32525]+[32038]+[30577]+[26194]+[13045]+[39135]+[51868]+[24530]+[8053]+[24159]+[6940]+[20820]+[62460]+[56306]+[37844]+[47995]+[12911]+[38733]+[50662]+[20912]+[62736]+[57134]+[40328]+[55447]+[35267]+[40264]+[55255]+[34691]+[38536]+[50071]+[19139]+[57417]+[41177]+[57994]+[42908]+[63187]+[58487]+[44387]+[2087]+[6261]+[18783]+[56349]+[37973]+[48382]+[14072]+[42216]+[61111]+[52259]+[25703]+[11572]+[34716]+[38611]+[50296]+[19814]+[59442]+[47252]+[10682]+[32046]+[30601]+[26266]+[13261]+[39783]+[53812]+[30362]+[25549]+[11110]+[33330]+[34453]+[37822]+[47929]+[12713]+[38139]+[48880]+[15566]+[46698]+[9020]+[27060]+[15643]+[46929]+[9713]+[29139]+[21880]+[10 |
This file contains hidden or 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
# The Gaussian periods modulo 257 | |
p = 257 | |
g = 3 (primitive root modulo 257) | |
# 1 dim'l Gaussian periods: | |
(256, 1) = [1]+[3]+[9]+[27]+[81]+[243]+[215]+[131]+[136]+[151]+[196]+[74]+[222]+[152]+[199]+[83]+[249]+[233]+[185]+[41]+[123]+[112]+[79]+[237]+[197]+[77]+[231]+[179]+[23]+[69]+[207]+[107]+[64]+[192]+[62]+[186]+[44]+[132]+[139]+[160]+[223]+[155]+[208]+[110]+[73]+[219]+[143]+[172]+[2]+[6]+[18]+[54]+[162]+[229]+[173]+[5]+[15]+[45]+[135]+[148]+[187]+[47]+[141]+[166]+[241]+[209]+[113]+[82]+[246]+[224]+[158]+[217]+[137]+[154]+[205]+[101]+[46]+[138]+[157]+[214]+[128]+[127]+[124]+[115]+[88]+[7]+[21]+[63]+[189]+[53]+[159]+[220]+[146]+[181]+[29]+[87]+[4]+[12]+[36]+[108]+[67]+[201]+[89]+[10]+[30]+[90]+[13]+[39]+[117]+[94]+[25]+[75]+[225]+[161]+[226]+[164]+[235]+[191]+[59]+[177]+[17]+[51]+[153]+[202]+[92]+[19]+[57]+[171]+[256]+[254]+[248]+[230]+[176]+[14]+[42]+[126]+[121]+[106]+[61]+[183]+[35]+[105]+[58]+[174]+[8]+[24]+[72]+[216]+[134]+[145]+[178]+[20]+[60]+[180]+[26]+[78]+[234]+[188]+[50]+[150]+[193]+[65]+[195]+[71] |
This file contains hidden or 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
module Dijkstra | |
# ノード全体を格納するクラス | |
class Nodes | |
def initialize | |
@done = false | |
@map = {} | |
end |
This file contains hidden or 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
# coding: utf-8 | |
require 'prime' | |
# Legendre symbol | |
def legendre(a, p) | |
p.times do |x| | |
if (x*x - a) % p == 0 then | |
return 1 |
This file contains hidden or 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
# zeta.rb | |
require 'complex' | |
LOWER_THRESHOLD = 1.0e-6 | |
UPPER_BOUND = 1.0e+4 | |
MAXNUM = 100 | |
module Zeta |