Loading...

연분수(continued fraction)를 이용한 선형 디오판토스 방정식의 해를 구하는 방법

1. 연분수 표현에서 a,b의 최대공약수를 바로 구하는 방법 $\frac{A}{B}$의 연분수 표현을 구하고자 한다면, A/B가 기약분수 형태로 들어가줘야한다. 기약분수로 바꿀려면 A,B의 최대공약수가 g = gcd(A,B)일때, $p_{k} = A/g, q_{k} = B/g$이고 그래서 $\frac{A}{B} = \frac{p_{k}}{q_{k}}$이다. 따라서, A/B가 기약분수가 아닐때, 연분수 표현 p,q를 구한 다음 A를 p[-1]로 나눠주면 A,B의 최대공약수가 된다. #A/B가 기약분수가 아닐때, A,B의 최대공약수 구하기 def continued_fraction(p,q): f = [] while q != 0: f.append(p//q) p,q = q,p%q return f def conve..

이항정리를 이용한 거듭제곱의 합 1^k+2^k+3^k+...+n^k 을 구하는 방법

1. 이항정리(binomial theorem) 0이상의 정수 n과 음이 아닌 정수 x,y에 대하여, $$(x+y)^{n} = \sum_{k = 0}^{n}\binom{n}{k}x^{k}y^{n-k}$$ https://en.wikipedia.org/wiki/Binomial_theorem Binomial theorem - Wikipedia From Wikipedia, the free encyclopedia Algebraic expansion of powers of a binomial In elementary algebra, the binomial theorem (or binomial expansion) describes the algebraic expansion of powers of a binomial. ..

gcd와 xor의 성질, 연속하는 두 자연수는 서로소, dict보다 list를 먼저 고려하기

1. 문제 21004번: GCD vs. XOR (acmicpc.net) 21004번: GCD vs. XOR For each test case output a single integer: the number of pairs $(a_i, a_j)$ with $i y이면 p-q ..

2023. 8. 13. 00:01

연속하는 두 소수 차이는 생각보다 크지 않다(prime gap)

https://en.wikipedia.org/wiki/Prime_gap Prime gap - Wikipedia Number 1 to 27 # gn pn n 1 1 2 1 2 2 3 2 3 4 7 4 4 6 23 9 5 8 89 24 6 14 113 30 7 18 523 99 8 20 887 154 9 22 1,129 189 10 34 1,327 217 11 36 9,551 1,183 12 44 15,683 1,831 13 52 19,609 2,225 14 72 31,397 3,385 15 86 155,921 14,357 16 96 360,653 30,802 17 en.wikipedia.org 1. 문제 23005번: Consecutive Primes (acmicpc.net) 23005번: Consecut..

n과 소수 p가 매우 클 때 wilson's theorem와 fermat's little theorem을 이용한 n! mod p 구하기

https://en.wikipedia.org/wiki/Wilson%27s_theorem Wilson's theorem - Wikipedia From Wikipedia, the free encyclopedia Theorem on prime numbers In algebra and number theory, Wilson's theorem states that a natural number n > 1 is a prime number if and only if the product of all the positive integers less than n is one less than a multip en.wikipedia.org https://namu.wiki/w/%EC%9C%8C%EC%8A%A8%EC%9D%9..

2023. 8. 4. 01:37

n이 매우 큰데 p가 매우 작은 경우에 효과적으로 n! mod p을 계산하는 방법

Factorial modulo p - Algorithms for Competitive Programming (cp-algorithms.com) Factorial modulo p - Algorithms for Competitive Programming Factorial modulo $p$ In some cases it is necessary to consider complex formulas modulo some prime $p$, containing factorials in both numerator and denominator, like such that you encounter in the formula for Binomial coefficients. We consider the case when c..