# Calculate arctan(1/x) using Taylor series with integer arithmetic
def arctan(x, decimals)
  scale = 10 ** (decimals + 10)
  x_squared = x * x
  
  result = 0
  term = scale / x
  
  n = 0
  while term != 0 && n < decimals * 3
    divisor = 2 * n + 1
    contrib = term / divisor
    
    if n % 2 == 0
      result += contrib
    else
      result -= contrib
    end
    
    term = term / x_squared
    n += 1
  end
  
  result
end

# Calculate pi using Machin's formula
def calculate_pi(decimals)
  atan1_5 = arctan(5, decimals)
  atan1_239 = arctan(239, decimals)
  
  16 * atan1_5 - 4 * atan1_239
end

# Format pi with decimal point
def format_pi(pi, decimals)
  pi_str = pi.to_s
  # Pad with leading zeros if needed
  while pi_str.length < decimals + 10
    pi_str = '0' + pi_str
  end
  "3.#{pi_str[1, decimals]}"
end

# Main
decimals = ARGV[0]&.to_i || 100
decimals = 100 if decimals <= 0

pi = calculate_pi(decimals)
print format_pi(pi, decimals)