Problem link: https://codeforces.com/problemset/problem/1766/D Question: If a number is correct ( x , y ) (x,y) (x,y) is lucky if and only if g c d ( x , y ) = 1 gcd(x,y)=1 gcd(x,y)=1, a chain can be composed of the following regular number pairs, ( x , y ) , ( x + 1 […]
Tag: sieve
Euler function and sieve method to find Euler function
Table of Contents Euler function Definition of Euler function Formula for the Euler function Formula derivation of Euler function Euler’s theorem Typical example Code Sieve method to find Euler function Idea analysis classic examples Code Euler function Definition of the Euler function For any positive integer no no n, the Euler function φ ( no […]
[2023 Hangdian Multi-School 5 1002] GCD Magic (Push formula, Mobius inversion, Dujiao sieve)
Title beg ∑ i = 1 no ∑ j = 1 no [ gcd ? ( 2 i ? 1 , 2 j ? 1 ) ] k \sum_{i = 1} ^ {n} \sum_{j = 1} ^ {n}[\gcd(2 ^ i – 1, 2 ^ j – 1)] ^ k i=1∑n?j=1∑n?[gcd(2i?1,2j?1)]k right 998 ? 244 ? […]
Weekly competition 352 (enumeration, Essieve + double pointer, double pointer)
Reference: https://leetcode.cn/circle/discuss/501Jzp/view/ICddVf/ In languages such as cpp, 1s can probably be counted as 1e8, and the time limit is generally 2s. Your algorithm can roughly calculate n based on n. For example, n is 1e5, and you wrote an n2 algorithm to calculate 1e10. Obviously, nlogn can definitely pass the calculation. According to the range […]
Find all prime numbers within the natural number n (general algorithm, Escherichia sieve method and Euler sieve method)
A prime number is also called a prime number, refers to a natural number greater than 1 that cannot be divisible by other natural numbers except 1 and the integer itself. In other words, a natural number that has only two positive factors (1 and itself) is a prime number. Numbers greater than 1 but […]
33. Mathematical knowledge – prime numbers (naive sieve method + Espersky sieve method + linear sieve method)
Main content of prime number and prime number sieve algorithm 1. Basic ideas 1. Prime numbers Determination of prime numbers – trial division (complexity fixed bit O(sqrt(n)) ) 2. Decompose the prime factor – trial division (the worst is O(sqrt(n))) 3. Simple sieve method – the sieve is a multiple 4. Essieve sieve method – […]
Prime number sieves (Euclidean sieve and Euler sieve)
We use leetcode204 question counting prime numbers to explain the prime number sieve problem Description of topic: Given an integer n , returns the number of all prime numbers less than a nonnegative integer n . Example 1: Input: n = 10 Output: 4 Explanation: There are 4 prime numbers less than 10, they are […]
(Mathematical knowledge) Judgment of prime numbers by trial division, decomposition of prime factors, Equation and linear sieve prime numbers
Prime numbers A prime number is a natural number that has no other factors than 1 and itself among the natural numbers greater than 1. Determination of prime numbers by trial division You will find that if a number is divided into two numbers and multiplied together, then the two numbers must appear in pairs, […]
[SSL 2402] The simplest radical (Dujiao sieve) (divisible into blocks)
The simplest radical Link to topic: SSL 2402 The main idea of the topic Ask multiple times, give you an n each time, and ask you how many a, b=2 so that any positive integer x has The k-time root opening of ax + b is not the simplest radical. Thoughts Consider correspondence a , […]