Number theory--factorization of mass factorization (C + +)

Source: Internet
Author: User

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 + +)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.