Loading...
2023. 8. 8. 03:06

문자열 해싱(hashing) 기본 개념 배우기

String Hashing - Algorithms for Competitive Programming (cp-algorithms.com) String Hashing - Algorithms for Competitive Programming String Hashing Hashing algorithms are helpful in solving a lot of problems. We want to solve the problem of comparing strings efficiently. The brute force way of doing so is just to compare the letters of both strings, which has a time complexity of $O(\mi cp-algori..

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..

2023. 8. 2. 00:15

3개 이상의 연속된 자연수의 합은 반드시 소수가 아니다

1. 연속된 자연수의 합 2개의 연속된 자연수를 합해보면.. 1+2 = 3 2+3 = 5 3+4 = 7 4+5 = 9 ... 소수가 나올 수 있는데 3개 이상의 연속된 자연수를 합해보면.. 1+2+3 = 6 2+3+4 = 9 3+4+5 = 12 4+5+6 = 15 ... 일단 소수가 보이질 않는다.. 이게 우연일까? 자연수 x에 대하여 n개의 연속된 자연수의 합은 다음과 같이 나타난다. $$S = x + (x+1) + (x+2) + ... + (x+n-1) = nx + \frac{(n-1)n}{2}$$ 여기서 n이 3이상의 자연수일때, S가 반드시 합성수임을 보이고자 한다. 1) 만약 n이 짝수라면 $n = 2k$ 여기서 k는 2이상의 자연수이다. $$S = 2kx + k(2k-1) = k(2x + 2k..

integer partition 문제1 - 합이 k가 되는 경우의 수 구하는 다이나믹 프로그래밍 익히기(구성이 같은데 순서가 다르면 같은 경우로 세는 방법, 다른 경우로 세는 방법)

1. 문제 9095번: 1, 2, 3 더하기 (acmicpc.net) 9095번: 1, 2, 3 더하기 각 테스트 케이스마다, n을 1, 2, 3의 합으로 나타내는 방법의 수를 출력한다. www.acmicpc.net 2. 풀이 정수 n을 1,2,3만 사용해서 만드는 방법의 수를 구하는 문제 1) 여기서 1,2,3은 중복해서 사용 가능하다 2) 동일하게 사용해도 순서가 다르면 다르다고 취급한다. 즉 1+1+2와 1+2+1은 다른 경우이다. dp[n]을 n을 만드는 방법의 수로 정의하고, 일단 n이 11보다 작기 때문에 dp의 크기를 11까지 잡아준다. n을 만들려면 어떻게 해야할까? 1,2,3만 사용할 수 있기 때문에 3가지 경우가 가능하다. 1) n-1에서 1을 더하면 n n-1을 만드는 방법의 수 dp..

10진법 정수를 등비수열 합으로 바라보기(Fermat number?)

1. 문제 22445번: Fast Division (acmicpc.net) 22445번: Fast Division イクタ君は速いプログラムが大好きである。最近は、除算のプログラムを高速にしようとしている。しかしなかなか速くならないので、「常識的に考えて典型的」な入力に対してのみ高速に www.acmicpc.net 일본어로 되어있는데 번역하면 $2^{2^{2^{2..}}}$로 총 2가 n개 있을때, 이 값보다 크거나 같은 최소의 소수를 p(n)이라고 정의하자. 여기서 p(0) = 2라고 한다. p(n)-1자리의 10진법 정수 1111....을 p(n)으로 나눈 나머지를 구한다면? 2. 풀이 p(n)을 한번 구해보면.. p(0) = 2 p(1) = 2보다 큰 최소의 소수 3 p(2) = 4보다 큰 최소의 소수 5 p(3) =..