A method for determining prime numbers based on the classification of mantissa and the non-intersection of functions
Patent Information
- Application Number
- CN202610952477.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-29
- Publication Date
- 2026-09-15
AI Technical Summary
[0003]概率性判定方法以Miller-Rabin算法为代表,该类方法存在卡迈克尔数等误判场景,判定结果不具备绝对确定性,无法满足密码学等高安全等级应用场景的使用需求
[0015] To further enhance compatibility with existing technologies and improve practical application efficiency, this invention can be combined with various mainstream judgment algorithms to construct a progressive hybrid judgment architecture. Through a multi-layered screening logic—including small-value comparison for prediction, Miller-Rabin rapid coarse screening, tail-number classification screening, and precise final judgment based on function non-intersection—it balances prediction speed with final judgment accuracy, adapting to numerical judgment needs across all scenarios. It is compatible with various operating environments such as ordinary terminals, servers, and encrypted devices, exhibiting excellent cross-platform compatibility.
Smart Images

Figure FT_1 
Figure FT_2
Abstract
Description
Technical Field
[0001] This invention belongs to the field of prime number detection algorithm technology, specifically involving a method for determining the prime of natural numbers based on tail number classification and functional non-intersection. Background Technology
[0002] Existing methods for determining prime numbers can be mainly divided into three categories: probabilistic methods, completely deterministic methods, and traditional trial division methods. All three types of methods have obvious defects.
[0003] Probabilistic judgment methods, represented by the Miller-Rabin algorithm, are prone to errors such as the Carmichael number, and the judgment results are not absolutely certain, which cannot meet the needs of high-security applications such as cryptography.
[0004] Completely deterministic decision-making methods are represented by algorithms such as ECPP and APR-CL. These algorithms have complex logical architectures, large code volumes (more than 20,000 lines), high deployment and maintenance costs, and are prone to runtime failures in practical applications.
[0005] Traditional trial division has a low application threshold, but it is extremely inefficient for determining prime numbers of very large integers with more than 100 digits. A single determination can take months or even years, making it completely unsuitable for real-time computing systems.
[0006] To address the shortcomings of the existing technologies, this invention proposes a deterministic prime number determination method that combines accurate determination, concise code, and high computational efficiency. Summary of the Invention
[0007] This invention proposes a deterministic prime number determination theory based on tail number classification and functional disjointness. This theory is mathematically complete and self-consistent, belonging to a completely deterministic determination scheme. This method does not rely on probability detection, random basis selection, or complex mathematical proofs; it can accurately determine prime and composite numbers solely through the set relationship between the objective function and the factor product function.
[0008] The core innovation principle of this invention is the function non-intersection determination logic. First, all candidate prime numbers that are not 2 or 5 are classified by their last digit, and only valid determination values with last digits of 1, 3, 7, and 9 are retained. Then, by constructing a dedicated objective function and factor product function, the existence of functional intersection relationship between the values to be determined is judged to accurately distinguish between prime numbers and composite numbers.
[0009] This invention establishes four core definitions to provide theoretical support for the entire determination method: the objective function is used to standardize the numerical expression of all candidate prime numbers, adapting to all large integers with last four digits of 1, 3, 7, and 9; the factor product function is derived based on the closing rule of last four digits in integer multiplication, accurately covering all factor combinations that can generate composite numbers; the function intersection is defined as the numerical value simultaneously satisfying both the objective function and the factor product function, thus determining it to be a composite number; the function non-intersection is defined as the numerical value only satisfying the objective function and having no matching factor product function, thus determining it to be a prime number.
[0010] The core innovation of this invention lies in configuring a unique combination of objective function and exclusive factor product function for each of the four valid mantissas. By fixing the matching relationship of mathematical functions, precise directional traversal is achieved, avoiding redundant calculations caused by traditional global traversal and significantly reducing the amount of computation. The complete function correspondence rules are as follows: First, for the value to be determined with mantissa K=1, the objective function is f(A)=10a+1, and the corresponding factor product functions include three sets: (10e+1)(10f+1), (10g+9)(10h+9), and (10i−7)(10j−3); Second, for the value to be determined with mantissa K=3, the objective function is f(A)= The factors for the first variable, 10b+3, are two sets: (10k+1)(10l−7) and (10m−3)(10n−1). The second variable, with a last digit K=7, has an objective function f(A)=10c+7, and its factors for the third variable, 10o+1)(10p−3) and (10q−7)(10r−1). The fourth variable, with a last digit K=9, has an objective function f(A)=10d+9, and its factors for the fifth variable, 10s−7)(10t−7), (10u+1)(10v+9), and (10w−3)(10x−3). All variables a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, and x are positive integers.
[0011] The table below summarizes the objective function, factor product function, and constraints corresponding to different last digits, clearly demonstrating the core judgment rules of this invention.
[0012] Table 1. Comparison of Objective Function and Factor Product Function for Different Tail Numbers
[0013] 1 (1,1)(9,9)(3,7) 10a+1 (10e+1)(10f+1), (10g+9)(10h+9), (10i−7)(10j−3) 10e+1, 10f+1, 10g+9, 10h+9, 10i-7, and 10j-3 all satisfy the condition that they are the arithmetic square roots of a natural number N that are greater than 2 and less than or equal to N. a, e, f, g, h, i, and j are all positive integers. 3 (1,3)(7,9) 10b+3 (10k+1)(10l−7), (10m−3)(10n−1) 10k+1, 10l-7, 10m-3, and 10n-1 all satisfy the condition that the arithmetic square root of the natural number N is greater than 2 and less than or equal to it. b, k, l, m, and n are all positive integers. 7 (1,7)(3,9) 10c+7 (10o+1)(10p−3), (10q−7)(10r−1) 10o+1, 10p-3, 10q-7, and 10r-1 all satisfy the condition that they are the arithmetic square roots of a natural number N that are greater than 2 and less than or equal to N. c, o, p, q, and r are all positive integers. 9 (3,3)(7,7)(1,9) 10d+9 (10s−7)(10t−7), (10u+1)(10v+9), (10w−3)(10x−3) 10s⁻⁷, 10t⁻⁷, 10u+1, 10v+9, 10w⁻³, and 10x⁻³ all satisfy the condition that they are the arithmetic square roots of a natural number N that are greater than 2 and less than or equal to N. d, s, t, u, v, w, and x are all positive integers.
[0014] This invention strictly limits the factor traversal range. All factors involved in the verification must satisfy the constraint that they are greater than 2 and less than or equal to the arithmetic square root of the natural number N to be determined, strictly adhering to the principle of uniqueness in composite number decomposition. Only when the natural number N to be determined simultaneously satisfies the objective function of its corresponding mantissa and is divisible by any set of corresponding factor product functions is it determined that the functions intersect, and N is a composite number. If N only satisfies the corresponding objective function but cannot match any factor product function, it is determined that the functions do not intersect, and N is a prime number. This determination rule can cover various scenarios for generating large integer composite numbers. The determination logic is complete, and the results are stable. While ensuring the completeness of the determination, it minimizes the traversal range to the greatest extent, solving the problem of redundant traversal in traditional trial division methods and significantly improving the efficiency of determining extremely large numbers.
[0015] To further enhance compatibility with existing technologies and improve practical application efficiency, this invention can be combined with various mainstream judgment algorithms to construct a progressive hybrid judgment architecture. Through a multi-layered screening logic—including small-value comparison for prediction, Miller-Rabin rapid coarse screening, tail-number classification screening, and precise final judgment based on function non-intersection—it balances prediction speed with final judgment accuracy, adapting to numerical judgment needs across all scenarios. It is compatible with various operating environments such as ordinary terminals, servers, and encrypted devices, exhibiting excellent cross-platform compatibility.
[0016] This invention is easy to implement, with the entire set of judgment code not exceeding 300 lines. It has a clear modular structure, no redundant logic, and can be directly deployed and run in Python 3.7 and above environments. It has strong cross-platform portability and can run stably on ordinary computers and embedded devices. It also supports operations on very large integers of hundreds and thousands digits.
[0017] Compared to existing technologies, this invention has four core advantages: First, it adopts a deterministic algorithm, resulting in stable judgments that meet the requirements of high-security encryption scenarios; second, it significantly improves computational efficiency by avoiding massive invalid calculations through tail-based traversal, far exceeding traditional trial division methods; third, it is extremely simple to deploy, with a code size far smaller than deterministic algorithms such as ECPP and APR-CL, resulting in extremely low maintenance costs; and fourth, it has wide adaptability, can be used independently or combined and optimized, and is suitable for judging any integer amount, from small to very large amounts.
[0018] Compared with existing technologies, the beneficial effects of this invention are as follows: This solution constructs a complete prime number determination theory based on mantissa classification and functional disjointness, which is logically complete and self-consistent; compared with Miller-Rabin-type probabilistic determination algorithms, the determination results are stable and can be adapted to high-security application scenarios such as cryptography; the entire determination program has a simple structure and small code size, and compared with deterministic algorithms such as ECPP and APR-CL, the deployment and maintenance costs are lower; relying on mantissa classification combined with directional factor traversal to reduce invalid calculations, the determination efficiency for large integers is better than the conventional trial division method; this solution can run independently or be combined with existing determination algorithms to build a multi-level screening architecture, adaptable to ordinary terminals, servers and embedded devices, and suitable for scenarios such as cryptographic encryption, information security, and basic mathematical research. Attached Figure Description
[0019] This invention includes two accompanying drawings to visually illustrate the judgment process.
[0020] Figure 1: Overall flowchart of prime number determination using the mixed method;
[0021] Figure 2: Flowchart for tail number classification and function non-intersection determination. Detailed Implementation
[0023] This invention is a method patent. The technical solution of this invention will be fully and thoroughly described below with reference to specific embodiments and program code. Those skilled in the art can fully reproduce the technical solution and operating effect of this invention based on this description.
[0024] Example 1: Standard method for determining prime numbers in large integers. The natural number to be determined, N=12347, is selected. First, the input validity is checked to confirm that the value is a valid positive integer greater than 2. The last digit of the value is calculated to be 7, which is a valid last digit, excluding even numbers and multiples of 5. The arithmetic square root of the value is calculated to be 111.12. Taking the upper limit of 111, the factor traversal interval is limited to greater than 2 and not greater than 111. The specific factor product function rule corresponding to the last digit 7 is called, and the factors of the corresponding specification are traversed sequentially and divisible. After the traversal, no valid divisible factors are found, the value only satisfies the objective function, and there are no intersecting functions. Finally, 12347 is determined to be a prime number.
[0025] Example 2: Prime Number Determination for Extremely Large Integers. The extremely large integer "10 to the power of 100 plus 7" is selected. This value has more than 100 digits, making it an extremely large number that traditional algorithms struggle to determine. First, the validity of the value is verified, confirming it as a valid extremely large positive integer. The last digit is fixed at 7, and the core determination process begins. The upper limit of the arithmetic square root is calculated based on the magnitude of the value, and a directional traversal is performed strictly according to the factor combination rules for the last digit 7. Factor verification is quickly completed across the entire range; no divisible factors are found, and there are no intersecting functions. Therefore, the number is definitively determined to be a prime number. This example successfully verifies the efficient adaptability of this invention to extremely large numbers.
[0026] Example 3: Complete Implementation of the Hybrid Method Program Code. This invention can implement all decision logic through modular Python code, including four types of tail-specific decision functions, a decimal comparison module, a Miller-Rabin prediction module, and a main program scheduling module. It completely replicates the core theory of this invention, with concise code, rigorous logic, and direct execution capability.
[0027] Large numerical values are first quickly filtered out obviously composite numbers using the Miller-Rabin algorithm to reduce the amount of subsequent calculations; then, a combination of a specific objective function and a factor product function is used to match the last digit, and the non-intersection of the functions is finally checked to accurately determine whether the value is a prime number or a composite number. The entire process is logically closed and can be completely reproduced.
[0028] Example of core code for implementing a function that determines non-intersection of functions ending in 7:
[0029]
Code Segment 1: Function to Determine if the Last Digit is 7
[0030] def function_judge_7(n, sqrt_n):
[0031] max_b = (sqrt_n - 1) / / 10
[0032] for b in range(1, max_b + 1):
[0033] x = 10 * b + 1
[0034] if n % x == 0:
[0035] y = n / / x
[0036] if y >= 2 and (y + 3) % 10 == 0:
[0037] return True
[0038] Example of the core code for the tail-number classification and final decision function:
[0039] [Code Segment 2: Main Function for Overall Judgment of Last Digit Classification]
[0040] import math
[0041] def final_prime_check(n):
[0042] k = n % 10
[0043] if k in (0, 2, 4, 5, 6, 8):
[0044] return False
[0045] sqrt_n = int(math.isqrt(n))
[0046] if k == 1:
[0047] return not function_judge_1(n, sqrt_n)
[0048] elif k == 3:
[0049] return not function_judge_3(n, sqrt_n)
[0050] elif k == 7:
[0051] return not function_judge_7(n, sqrt_n)
[0052] elif k == 9:
[0053] return not function_judge_9(n, sqrt_n)
[0054] return False.
Claims
1. A method for determining the prime number of a natural number, characterized in that, The natural numbers greater than 1 are filtered, and for those greater than 2, a primality test is performed, including the following steps: Step 1: Filter the natural numbers N to be judged that end in 1, 3, 7, or 9, and construct the objective function f(A) = 10a + K, where a and K are both natural numbers, and K is the last digit of the natural number N; Step 2: Based on the rules of multiplying the last digits of integers, construct a factor product function to determine composite numbers. All factors in the factor product function take values greater than 2 and less than or equal to the arithmetic square root of the natural number N. Step 3: Determine whether the natural number N satisfies both the objective function and any factor product function. If it does, then the natural number N is a composite number. If the natural number N only satisfies the objective function but not any factor product function, then the natural number N is a prime number.
2. The method for determining the prime number of a natural number according to claim 1, characterized in that, Different mantissas K correspond to different factor product functions: When K=1, the corresponding factor product functions are (10e+1)(10f+1), (10g+9)(10h+9), and (10i−7)(10j−3); When K=3, the corresponding factor product functions are (10k+1)(10l−7) and (10m−3)(10n−1); When K=7, the corresponding factor product functions are (10o+1)(10p−3) and (10q−7)(10r−1); When K=9, the corresponding factor product functions are (10s−7)(10t−7), (10u+1)(10v+9), and (10w−3)(10x−3); Where e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, and x are all positive integers.