Created
August 2, 2026 20:02
-
-
Save Hermann-SW/7079cd78d10b5bc690c5843a8c5bf057 to your computer and use it in GitHub Desktop.
Synthetic benchmark from long gemini session for >170 TFLOPS FP8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <cstdint> | |
| #include <cuda_runtime.h> | |
| #define CUDA_CHECK(status) \ | |
| do { \ | |
| cudaError_t err = (status); \ | |
| if (err != cudaSuccess) { \ | |
| std::cerr << "[CUDA Error] " << cudaGetErrorString(err) \ | |
| << " (" << err << ") at line " << __LINE__ << std::endl; \ | |
| exit(EXIT_FAILURE); \ | |
| } \ | |
| } while (0) | |
| #define UNROLL_FACTOR 32 | |
| __global__ void __launch_bounds__(256, 2) fp8_ptx_peak_kernel_optimized(int64_t iterations) { | |
| uint32_t a[4] = {0x3c003c00, 0x3c003c00, 0x3c003c00, 0x3c003c00}; | |
| uint32_t b[2] = {0x3c003c00, 0x3c003c00}; | |
| // 4 independent sets of accumulators to break latency dependency chain | |
| float c0[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | |
| float c1[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | |
| float c2[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | |
| float c3[4] = {0.0f, 0.0f, 0.0f, 0.0f}; | |
| for (int64_t i = 0; i < iterations; ++i) { | |
| #pragma unroll | |
| for (int u = 0; u < UNROLL_FACTOR; ++u) { | |
| asm volatile ( | |
| "mma.sync.aligned.kind::f8f6f4.m16n8k32.row.col.f32.e4m3.e4m3.f32 {%0,%1,%2,%3}, {%4,%5,%6,%7}, {%8,%9}, {%0,%1,%2,%3};\n" | |
| "mma.sync.aligned.kind::f8f6f4.m16n8k32.row.col.f32.e4m3.e4m3.f32 {%10,%11,%12,%13}, {%4,%5,%6,%7}, {%8,%9}, {%10,%11,%12,%13};\n" | |
| "mma.sync.aligned.kind::f8f6f4.m16n8k32.row.col.f32.e4m3.e4m3.f32 {%14,%15,%16,%17}, {%4,%5,%6,%7}, {%8,%9}, {%14,%15,%16,%17};\n" | |
| "mma.sync.aligned.kind::f8f6f4.m16n8k32.row.col.f32.e4m3.e4m3.f32 {%18,%19,%20,%21}, {%4,%5,%6,%7}, {%8,%9}, {%18,%19,%20,%21};\n" | |
| : "+f"(c0[0]), "+f"(c0[1]), "+f"(c0[2]), "+f"(c0[3]), | |
| "+f"(c1[0]), "+f"(c1[1]), "+f"(c1[2]), "+f"(c1[3]), | |
| "+f"(c2[0]), "+f"(c2[1]), "+f"(c2[2]), "+f"(c2[3]), | |
| "+f"(c3[0]), "+f"(c3[1]), "+f"(c3[2]), "+f"(c3[3]) | |
| : "r"(a[0]), "r"(a[1]), "r"(a[2]), "r"(a[3]), | |
| "r"(b[0]), "r"(b[1]) | |
| ); | |
| } | |
| } | |
| if (threadIdx.x == 0 && c0[0] == 12345.0f) { | |
| printf("Sink: %f\n", c0[0] + c1[0] + c2[0] + c3[0]); | |
| } | |
| } | |
| int main() { | |
| CUDA_CHECK(cudaFree(0)); | |
| int device = 0; | |
| cudaDeviceProp prop; | |
| CUDA_CHECK(cudaGetDeviceProperties(&prop, device)); | |
| std::cout << "Benchmarking Device: " << prop.name << " (" << prop.multiProcessorCount << " SMs)" << std::endl; | |
| int threads_per_block = 256; | |
| int num_blocks = prop.multiProcessorCount * 8; // Higher occupancy | |
| int64_t iterations = 50000; | |
| // Warmup | |
| fp8_ptx_peak_kernel_optimized<<<num_blocks, threads_per_block>>>(iterations / 10); | |
| CUDA_CHECK(cudaDeviceSynchronize()); | |
| cudaEvent_t start, stop; | |
| CUDA_CHECK(cudaEventCreate(&start)); | |
| CUDA_CHECK(cudaEventCreate(&stop)); | |
| CUDA_CHECK(cudaEventRecord(start)); | |
| fp8_ptx_peak_kernel_optimized<<<num_blocks, threads_per_block>>>(iterations); | |
| CUDA_CHECK(cudaEventRecord(stop)); | |
| CUDA_CHECK(cudaEventSynchronize(stop)); | |
| float ms = 0.0f; | |
| CUDA_CHECK(cudaEventElapsedTime(&ms, start, stop)); | |
| int total_warps = (num_blocks * threads_per_block) / 32; | |
| // 4 MMA instructions per unroll loop step | |
| double total_mma_ops = (double)total_warps * iterations * UNROLL_FACTOR * 4.0; | |
| double total_flops = total_mma_ops * 8192.0; | |
| double seconds = ms / 1000.0; | |
| double tflops = (total_flops / seconds) / 1e12; | |
| std::cout << "Execution Time: " << ms << " ms" << std::endl; | |
| std::cout << "Raw Peak FP8 Tensor Core Performance: " << tflops << " TFLOPS" << std::endl; | |
| CUDA_CHECK(cudaEventDestroy(start)); | |
| CUDA_CHECK(cudaEventDestroy(stop)); | |
| return 0; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unrelated.
hermann@7600x:~/llama.cpp$ HIP_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 ./build/bin/llama-cli
-m hf/BF16/Qwen3.8-27B-BF16-00001-of-00002.gguf
--no-mmap
-c 32768
-fa on
-sm layer
-ts 1,1,1,1,1,1,1,2
--cache-type-k f16
--cache-type-v f16
-ngl 99
--jinja
-p "Hello! Give me a summary of fast integer factorization techniques."
Loading model...
▄▄ ▄▄
██ ██
██ ██ ▀▀█▄ ███▄███▄ ▀▀█▄ ▄████ ████▄ ████▄
██ ██ ▄█▀██ ██ ██ ██ ▄█▀██ ██ ██ ██ ██ ██
██ ██ ▀█▄██ ██ ██ ██ ▀█▄██ ██ ▀████ ████▀ ████▀
██ ██
▀▀ ▀▀
build : b10489-169e4a7ff
model : hf/BF16/Qwen3.8-27B-BF16-00001-of-00002.gguf
ftype : BF16
modalities : text
available commands:
/exit or Ctrl+C stop or exit
/regen regenerate the last response
/clear clear the chat history
/read add a text file
/glob add text files using globbing pattern
[Start thinking]
We need to respond to user: "Hello! Give me a summary of fast integer factorization techniques." Need final answer. Need summarize fast integer factorization techniques. Could include algorithms: trial division, Pollard rho, Pollard p-1, ECM, quadratic sieve, number field sieve, general number field sieve, special number field sieve, Coppersmith-Winograd? Also mention complexity, applicability, use in practice, maybe modern records. Need be accurate.
Need likely provide concise but detailed. User asks summary. We can organize by small/medium/large, deterministic vs probabilistic, algebraic number theory. Mention no known polynomial-time classical; quantum Shor polynomial time. Include bit complexity.
Let's craft. Need maybe mention factorization of smooth integers? "fast integer factorization techniques" maybe computational number theory.
Content:
Number field sieve:
L_N[α,c] = exp((c+o(1))(ln N)^α (ln ln N)^{1-α}).
QS: α=1/2, c=sqrt(2) ≈1.414.
NFS: α=1/3, c=(64/9)^{1/3} ≈1.923. This is for both GNFS and SNFS? SNFS same asymptotic exponent but lower constant? I think SNFS complexity often stated exp((64/9)^{1/3} + o(1) (ln N)^{1/3} (ln ln N)^{2/3}) too. Special NFS may have lower constant depending on polynomial; but asymptotic same as GNFS? Some sources: SNFS L_N[1/3, (64/9)^{1/3}], GNFS L_N[1/3, (64/9)^{1/3}]? Yes. But special NFS often faster in practice by factor maybe 2-10, and can handle numbers like Mersenne (2^p-1) much larger.
Need ensure not overstate. Let's think through complexities.
Definitions: bit length n = log2 N, decimal digits d ~ n/log2(10). Trial division to sqrt(N): O(sqrt N) time = exp(Theta(n)).
Fermat: if N = a^2 - b^2, factors a±b; number iterations ~ (p-q)^2/(4N)? If p and q close, fast. Complexity O(|p-q|^2/N) maybe; if factors within O(sqrt N) then okay.
Pollard rho: For smallest prime p, expected O(sqrt p) modular multiplications; memory O(1). Good up to p ~ 10^12-10^18 depending implementation.
Pollard p-1: Stage 1 O(B log N), stage 2 O(B' log N / ln B')? If p-1 B-smooth, find p. Good for p with smooth p-1.
ECM: For prime p, expected O(exp(1/2 sqrt(ln p ln ln p))) group ops with memory O(exp(1/4 sqrt...? Actually memory maybe less). Finds factors p up to about 60-80 decimal digits? Need careful: ECM can find 70-digit factors? The record? ECM has found factors with up to 77 decimal digits? As of 2020, ECM found 77-digit factors? Actually ECM can factor 70+ digit primes; used to remove small factors from 200-digit numbers. It is best for factors up to ~50-70 decimal digits? Let's phrase: very effective for factors up to a few tens of digits (often 20–80 decimal digits, depending on resources).
QS: factoring generic N with ~100-150 decimal digits. Complexity L[1/2, sqrt(2)].
NFS: best for large generic N, >150 digits. Complexity L[1/3, 1.923].
SNFS: for special form a^b ± c; same asymptotic but lower constant; can factor Mersenne/Fermat-like numbers much larger.
Coppersmith? There is Coppersmith's algorithm for finding small roots, not factorization? Could be used to factor if small factor? Not general.
Maybe mention "fast integer factorization" in cryptography: RSA security relies on hardness; best classical algorithms subexponential.
Potential issue: "fast" could be in programming contest: quick factorization for 64-bit? But user asks general. Provide summary.
Need maybe include practical pipeline:
Need maybe mention parallelism: NFS sieving linear algebra parallelizable.
Need maybe include examples of current limits: As of 2020s, GNFS can factor ~800-bit (240 decimal digit) integers with large clusters; SNFS can handle much larger Mersenne forms? But careful: Factoring Mersenne composites with SNFS maybe 1000+ bits? There are records: SNFS factored 1024-bit Mersenne? Not sure. General NFS record RSA-240 (795 bits). Special NFS for Mersenne? There is factorization of 1024-bit Mersenne? Actually Mersenne composites may be factored by SNFS. But avoid exact records.
Let's craft final with headings, table. Need be clear.
Potential complexities:
Could include "SQUFOF" for 64-bit: often fastest for medium-sized factors under 64 bits? Complexity O(N^{1/4})? SQUFOF expected O(N^{1/4})? Actually SQUFOF finds factor p in O(sqrt p) too? It is a variant of Fermat, good for 32/64-bit. But maybe too much.
Need final answer likely: "Hello! Here's a summary..." Good.
Let's ensure no false claims:
Need maybe mention "fast" relative to size:
Potential table columns: Method, best for, rough complexity/behavior, notes.
Let's craft final with enough detail but not too long. The desired oververbosity 9 means detailed. We can include "practical pipeline".
Need maybe mention "integer factorization techniques" could include "fast" for arbitrary precision in libraries: GMP, PARI, CADO-NFS, msieve. Could mention tools: yafu, msieve, CADO-NFS, PARI/GP, GMP-ECM, NTRU? Maybe optional.
Let's structure:
Need be precise with bit lengths:
Let's consider if user expects "fast integer factorization techniques" from algorithms class: maybe mention quadratic sieve, number field sieve, elliptic curve. We'll include.
Need maybe mention "smoothness" concept: methods find factors by discovering smooth values and relations.
Let's write final:
Then table.
Potential pitfalls:
Pollard p-1 complexity stage 2: O(B' log N / log B')? Let's not over-specific.
ECM complexity: maybe O(exp(1/2 sqrt(ln p ln ln p))) group operations per curve; to find a factor p, need some number of curves; heuristic.
Fermat method: complexity O(sqrt N) worst-case, but fast if p and q close. It is not generally "fast" unless close.
Trial division: if using precomputed primes up to x, finds small factors.
SQUFOF: O(N^{1/4})? Let's verify. Shanks's square forms factorization has heuristic complexity O(N^{1/4})? For N with small factor p, complexity O(p^{1/2})? Actually SQUFOF is a square forms algorithm; expected O(N^{1/4}) to factor N? I recall SQUFOF is faster than Fermat and Pollard rho for 64-bit? It has heuristic O(N^{1/4}) = O(sqrt p) if p ~ sqrt N? If p is small, maybe O(p^{1/2})? Let's check: SQUFOF expected time O(N^{1/4}) to find a factor. For N ~ p^2, that's O(p^{1/2}), same as Pollard rho. Good. We can mention "often very fast for 32/64-bit integers".
Continued fraction method: predecessor to QS, complexity exp(c sqrt(ln N ln ln N)) with larger constant than QS. Could mention as historical.
Dixon's method: O(exp(1/2 sqrt(ln N ln ln N)))? Actually Dixon's random method has same complexity as QS? It was first subexponential? Let's not include.
Algebraic number field sieve steps: polynomial selection, sieving, linear algebra, root extraction. Could mention.
Special forms: cyclotomic factorization, Aurifeuillean, algebraic identities; e.g., a^n ± b^n.
Quantum: Shor.
Need maybe mention "fast integer factorization" in cryptographic context: RSA key sizes. Could say "For RSA-sized numbers (2048-bit), classical factorization is infeasible with current GNFS; estimated resources enormous." Maybe not necessary but useful.
Let's craft final in a friendly tone.
Double-check complexities:
L_N[α,c] = exp((c+o(1)) (ln N)^α (ln ln N)^{1-α}). For QS α=1/2, c=√2. For NFS α=1/3, c=(64/9)^{1/3}. Good.
ECM: expected O(exp(1/2 sqrt(ln p ln ln p))) modular operations. Some sources: ECM complexity O(e^{(1/2+o(1))√(ln p ln ln p)}). Yes.
Pollard p-1: if p-1 is B-smooth, stage 1 O(B log N) modular exponentiations/multiplications. Stage 2 maybe O(B' log N / ln B'). Good.
Need maybe mention "probability" for Pollard rho/ECM; deterministic primality tests separate. Factorization algorithms often randomized; can fail but repeat.
Let's prepare final:
Need maybe avoid too much. But desired oververbosity high, so detailed.
Let's think of exact phrasing for SNFS: "SNFS applies when N = a^b ± c with small a,c (or related forms), e.g., Mersenne numbers 2^p - 1 or numbers close to a perfect power. It uses a simpler polynomial and can be much faster than GNFS for such N, but is not applicable to arbitrary RSA moduli." Good.
Could mention "GNFS can be parallelized, but linear algebra memory bottleneck".
Could include "Current classical frontier: factoring ~700–800 bit generic integers with GNFS is a major cluster computation; 1024+ bit RSA is infeasible." Is that accurate? RSA-240 795 bits factored in 2020. In 2025 maybe RSA-250? I think no. 829-bit? There may be new record? Let's be cautious: "around 800-bit generic integers have been factored". Good.
Need maybe mention "NFS is the algorithm behind RSA security estimates". Good.
Let's ensure not to imply SNFS asymptotically faster than GNFS in L exponent if not. We can say "same subexponential form but smaller constants and much easier polynomial selection". For Mersenne, specialized NFS can factor larger bit lengths than GNFS.
Potential addition: "For 32-bit integers, trial division up to 2^16 or Pollard rho enough; for 64-bit, Pollard rho/SQUFOF; for 128-bit semiprimes with 64-bit factors, Pollard rho feasible; for 256-bit, ECM/QS/NFS." Maybe include.
Need maybe mention "integer factorization vs primality testing". Could mention Miller-Rabin first.
Let's draft final with table. Ensure final answer only. Use markdown.
One more nuance: "fast integer factorization techniques" might ask for "summary" not exhaustive. We can keep around 1000-1500 words? Oververbosity 9 but not too huge. Let's aim ~1200-1600 words.
Let's formulate:
Maybe table after prose.
Let's include "Smoothness" in QS/NFS: find many values x such that f(x) is B-smooth, build relations, solve linear system over GF(2), get square relation. For NFS, use number fields to reduce size of numbers being sieved.
ECM details: works on elliptic curves over Z/NZ; for a prime factor p, curve group order divisible by p with high probability; repeated multiplication collapses mod p, gcd reveals p. Good for small factors.
Pollard rho details: random map f(x)=x^2+c mod N; Floyd/Brent cycle detection; gcd(|x-y|, N). Good for small factors.
Pollard p-1 details: compute a^M mod N with M multiple of lcm(1..B); if p-1 divides M, gcd(a^M-1,N) yields p.
SQUFOF: continued fraction / square forms; low memory, fast for 64-bit.
Fermat: write N=a^2-b^2. Good if p and q close.
Quadratic sieve: choose m≈√N, sieve values m^2 - N for smoothness, linear algebra over GF(2), produce square congruence.
GNFS: choose polynomial f,g with common root mod N? More precisely f(a) ≡ 0 mod N; use norm forms in number field and integers to find smooth pairs. Sieve over two surfaces. Linear algebra. Root extraction.
Special NFS: for N = a^b ± c, choose f(x)=x^b ∓ c? Norm forms simpler.
Special algebraic factorization: if N has algebraic form, factor symbolically before numeric: x^n±y^n, cyclotomic polynomials, Aurifeuillean.
Quantum: Shor's algorithm finds order and factors in polynomial time; requires fault-tolerant quantum computer.
Practical pipeline:
Need maybe mention "libraries: CADO-NFS, msieve, PARI/GP, yafu, GMP-ECM, NTL". Could include as note.
Let's write final. Ensure no analysis. final.
[End thinking]
Hello! Here’s a high-level summary of the main fast integer factorization techniques, roughly ordered from “small numbers / small factors” to “large cryptographic-sized numbers.”
1. Complexity notation
For large integers, factorization algorithms are usually described using the subexponential notation
[
L_N[\alpha, c] =
\exp\left((c+o(1))(\ln N)^\alpha (\ln \ln N)^{1-\alpha}\right).
]
A smaller (\alpha) is much better. The best classical general-purpose factorization algorithm, the Number Field Sieve, has
[
L_N[1/3, (64/9)^{1/3}],
]
which is subexponential but still far beyond polynomial time.
2. Small-factor and quick methods
These are useful before attempting a full large-scale factorization.
Trial division
Idea: Test divisibility by small primes: (2,3,5,7,\dots)
Complexity:
If you divide up to (\sqrt{N}), worst-case time is roughly
[
O(\sqrt{N})
]
or exponential in the bit-length of (N).
Use:
Good only for tiny integers, or for removing very small prime factors from larger numbers.
Fermat’s method
Idea: Write
[
N = a^2 - b^2 = (a-b)(a+b).
]
Start near (a = \lceil \sqrt{N} \rceil) and increase (a) until (a^2 - N) is a perfect square.
Complexity:
Worst case is poor, but it is very fast when the two factors are close together.
Use:
Useful if (N = pq) with (p \approx q). Not generally fast for arbitrary integers.
Pollard’s rho algorithm
Idea: Simulate a random walk modulo (N):
[
x_{i+1} = f(x_i) \pmod{N},
]
usually (f(x)=x^2+c). Detect a cycle using Floyd’s or Brent’s cycle-finding method. If (x \ne y \pmod N) but (x \equiv y \pmod p) for a prime factor (p), then
[
\gcd(x-y, N)
]
may reveal (p).
Complexity:
For a smallest prime factor (p), expected time is about
[
O(\sqrt{p})
]
modular operations.
Use:
Very effective for finding small or medium-sized prime factors, often up to around 40–64 bits, depending on implementation and hardware.
Pollard’s (p-1) method
Idea: If (p) is a prime factor of (N) and (p-1) is smooth, meaning its prime factors are all small, then for a suitable multiple (M) of (1,2,\dots,B),
[
a^M \equiv 1 \pmod p.
]
Then
[
\gcd(a^M - 1, N)
]
may reveal (p).
Complexity:
If (p-1) is (B)-smooth, roughly
[
O(B \log N)
]
modular multiplications/exponentiations in stage 1, with an optional stage 2 to extend the smoothness bound.
Use:
Fast when (p-1) has only small prime factors. Common as a quick pre-factorization step.
SQUFOF
SQUFOF stands for Shanks’s Square Forms Factorization.
Idea: A continued-fraction-based method related to Fermat’s method. It searches for a square form representation of (N).
Complexity:
Heuristic time is around
[
O(N^{1/4})
]
for general use, and very fast in practice for 32-bit and 64-bit integers.
Use:
Often one of the fastest methods for 64-bit integers, especially when Pollard rho is not needed.
Elliptic Curve Method, ECM
Idea: Use elliptic curves modulo (N). For a prime factor (p) of (N), with reasonable probability, the group order of a random elliptic curve modulo (p) is smooth enough that repeated point multiplication collapses modulo (p). Taking a gcd then reveals (p).
Complexity:
For a prime factor (p), heuristic expected cost is about
[
\exp\left(\frac12 \sqrt{\ln p \ln \ln p}\right)
]
group operations.
Use:
ECM is one of the best methods for finding medium-sized prime factors, often in the range of tens of decimal digits, e.g. 20–70 digit factors depending on resources. It is commonly used to remove small factors before running larger algorithms such as the Number Field Sieve.
3. General large-integer factorization
For large arbitrary integers, the main classical methods are sieve-based.
Continued Fraction Method
Idea: Use continued fractions of (\sqrt{N}) to find relations that produce a square congruence modulo (N).
Complexity:
Subexponential, similar in shape to the Quadratic Sieve but with worse constants.
Use:
Historically important, but mostly superseded by the Quadratic Sieve.
Quadratic Sieve, QS
Idea: Choose (m \approx \sqrt{N}). Sieve values of
[
m^2 - N
]
to find many values that are (B)-smooth, meaning they factor only over a small prime set. These smooth values give multiplicative relations. Combine them to create a square congruence:
[
x^2 \equiv y^2 \pmod N.
]
Then
[
\gcd(x-y, N)
]
may reveal a factor.
Complexity:
[
L_N[1/2, \sqrt{2}]
\exp\left((\sqrt{2}+o(1))\sqrt{\ln N \ln \ln N}\right).
]
Use:
The Quadratic Sieve is the standard method for medium-sized integers, often up to around 80–140 decimal digits, depending on resources. It was long the record holder and is still used for smaller large integers.
General Number Field Sieve, GNFS
Idea: The General Number Field Sieve is currently the fastest classical algorithm for factoring large arbitrary integers.
It uses algebraic number theory. Roughly:
Complexity:
[
L_N\left[1/3, (64/9)^{1/3}\right]
\exp\left(
\left((64/9)^{1/3}+o(1)\right)
(\ln N)^{1/3}(\ln \ln N)^{2/3}
\right).
]
Use:
GNFS is the main classical algorithm for factoring large generic integers, especially RSA-sized or larger numbers. Factoring around 700–800-bit generic integers is possible only with large distributed computing efforts.
Practical notes:
4. Special-form factorization
Some integers have algebraic structure that can be exploited.
Special Number Field Sieve, SNFS
Idea: If (N) has a special form, for example
[
N = a^b \pm c
]
with small (a) and (c), then the polynomial choice in the Number Field Sieve is much simpler.
Complexity:
Asymptotically similar to GNFS:
[
L_N\left[1/3, (64/9)^{1/3}\right],
]
but with smaller constants and often much faster in practice.
Use:
Especially useful for numbers like:
SNFS can factor special-form numbers much larger than arbitrary numbers of the same bit length.
Algebraic factorization
If (N) can be written in a special algebraic form, it may factor symbolically before any numerical factorization is attempted.
Examples:
[
x^n - y^n = (x-y)(x^{n-1}+x^{n-2}y+\cdots+y^{n-1}),
]
[
x^n + y^n
]
for odd (n),
and various cyclotomic or Aurifeuillean identities.
Use:
Very fast when applicable, but only for integers with exploitable algebraic structure.
5. Quantum factorization
Shor’s algorithm
Idea: Use a quantum computer to find the period of a function modulo (N), then derive a nontrivial square root of (1) modulo (N), giving a factor.
Complexity:
Polynomial in the bit-length of (N), roughly (O(n^3)) with standard implementations, up to constants and circuit overhead.
Use:
Shor’s algorithm would break RSA and many other public-key cryptosystems, but requires a large, fault-tolerant quantum computer. It is not currently practical at cryptographic scale.
6. Practical factorization pipeline
In practice, one usually tries methods in order of increasing cost:
Trial division
Remove very small prime factors.
Primality test
Use Miller–Rabin, AKS, BPSW, etc., to check whether the number is prime.
Quick algebraic checks
Check for perfect powers, cyclotomic forms, Fermat differences, etc.
Pollard’s rho / SQUFOF
Find small-to-medium factors efficiently.
Pollard (p-1)
Useful if (p-1) is likely smooth.
Elliptic Curve Method
Find medium-sized prime factors.
Quadratic Sieve
Factor medium-sized arbitrary integers.
General Number Field Sieve
Factor large arbitrary integers.
Special Number Field Sieve
Use if the integer has special algebraic form.
Quantum, if available
Shor’s algorithm is polynomial-time but not currently practical at scale.
7. Quick comparison table
Bottom line
For small integers, use trial division, Pollard rho, SQUFOF, or Fermat.
For medium-sized factors, ECM is often the workhorse.
For large arbitrary integers, the General Number Field Sieve is the current classical champion.
For special forms, the Special Number Field Sieve or algebraic identities can be dramatically faster.
And for the quantum future, Shor’s algorithm is the theoretical polynomial-time method.
[ Prompt: 23.2 t/s | Generation: 9.6 t/s ]