본문 바로가기

math

(4)
파이썬 지수 수치계산방식에 따른 차이 """ calculate 50000 / n \ | 10 - 1 | | ------------ | | n | \ 10 / """ import math def f(n): return ((10 ** n - 1) / (10 ** n)) ** 50000 def f2(n): return (1 - 10 ** (-n)) ** 50000 def f_exp10_log10(n): exponent = 50000 * (math.log10(10 ** n - 1) - n) return 10 ** exponent def f_exp2_log2(n): exponent = 50000 * (math.log2(10 ** n - 1) - n * math.log2(10)) return 2 ** exponent def f_exp_ln(n): ex..
[EP 005] least common multiple for a list of numbers #################################################### # http://projecteuler.net # # Problem 5 # # 2520 is the smallest number that can be divided # by each of the numbers from 1 to 10 without any # remainder. # # What is the smallest number that is evenly # divisible by all of the numbers from 1 to 20? #################################################### # Author : DwYoon # Date : 2007 04 12 N = ..
구에서 좌표사이의 거리 구하기 직교좌표계에서 내적을 구하는 건 매우 간단하다. 내적은 단위원 위의 두 벡터에 대해서는 두 벡터 사이의 사이각의 코사인. 최단거리이기 때문에 180도 이상인지 이하인지는 중요하지 않다. 그래서 내적의 역코사인에 구의 반지름을 곱하면 답. void GetCartesian(double Lat, double Long, double *x, double *y, double *z) { /* 유사구면좌표계를 직교좌표계로 변환. http://ko.wikipedia.org/wiki/%EA%B5%AC%EB%A9%B4_%EC%A2%8C%ED%91%9C%EA%B3%84 */ *x = cos(Lat)*cos(Long); *y = cos(Lat)*sin(Long); *z = sin(Lat); } double Calc1(doubl..
[파이썬] 이집트분수 >>> def egypt(x): ''' x = (a, b) which represent a/b ''' r = [] while x[1]%x[0]: m = x[1]//x[0] + 1 r.append(m) x = (x[0]*m - x[1], x[1]*m) r.append(x[1]//x[0]) print('+'.join('1/%d'%d for d in r)) return r >>> egypt((4, 5)) 1/2+1/4+1/20 [2, 4, 20] >>> egypt((2, 11)) 1/6+1/66 [6, 66] >>> egypt((761, 1000)) 1/2+1/4+1/91+1/91000 [2, 4, 91, 91000] 분수의 이집트분수 분해를 구하는 코드. 버그 없는지 잘 모르겠는데, 일단 깔끔하게 됨.