2011-01-01ãã1å¹´éã®è¨äºä¸è¦§
math.hã®sqrt(f)ã使ããã«æ´æ°ã®å¹³æ¹æ ¹ãæ±ãã¦ã¿ãã(intã4byteã§ãããã·ã³ã§ã®ã¿åä½) sqrtmod0ã¯ã¢ã«ã´ãªãºã ä¸0x40000000以ä¸ã®å¤ã®å¹³æ¹æ ¹ãè¨ç®ã§ãããªã®ã§ã0x40000000以ä¸ã®å¤ã¯Karatsubaéå¹³ãå©ç¨ãã¦æ±ãã¦ãããâã¯ä¹±æ°ã§å¹³æ¹æ ¹ã¨ä½ããæ±ãâ¦
æ¤è¨¼ç¨ã«ä½¿ã£ã¦ããç©ã§ãã len = ARGV[0].to_i B = 10 ** len B2 = B << 1 pi = (len * 8 + 1).step(3, -2).inject(B) {|a, i| (i >> 1) * (a + B2) / i} - B puts "3.#{pi}" # time ruby pi.rb 100 3.14159265358979323846264338327950288419716939937510â¦