First, the structural quality tables
(1) Trial Division
Source:
#include <cstdio>
int N,s (1), i[1001];
int main ()
{
scanf ("%d", &n);
i[1]=2;
printf ("2");
for (int a=3;s<n;a++)
{
bool T (0);
for (int b=1;b<=s;b++)
if (! ( A%I[B]))
t=true;
if (!t)
{
s++;
I[s]=a;
printf ("%d", a);
}
}//Use the former prime number to test the current numbers, and to construct the mass tables more quickly.
return 0;
}
(2) Sieve method
Source:
#include <cstdio>
int n,s (0);
BOOL F[100001]={0};
int main ()
{
scanf ("%d", &n);
for (int a=2;s<n;a++)
if (!f[a])
{
printf ("%d", a);
for (int b=2;b<=100;b++)//This loop variable and the range of the array should also be practical.
F[b*a]=true;
s++;
}
return 0;
}
Two, Pollard Rho algorithm
Source:
#include <cstdio>
int n;
void X1 (int t,int k)
{
if (t==k)
printf ("%d", k);
Else
if (! ( T%K))
{
printf ("%d*", k);
X1 (t/k,k);
}
Else
X1 (t,k+1);
}//use wonderful rules to make recursion.
int main ()
{
scanf ("%d", &n);
X1 (n,2);
return 0;
}
Number theory--factorization of mass factorization (C + +)