Does anyone know how gmp works? It's supposedly installed but I don't know how to use the functions. I try following this site http://es-sun2.fernuni-hagen.de/cgi-bin/info2html?(gmp)Top but it doesn't compile when I try using the functions.

What I'm trying to do is factor a large number. Is there an mpz function for it? Or does anyone have another way? Thanks

OK I can use the mpg a little now. I'm implementing RSA encryption. I'm still having a problem with factorization. I want to make a function for factoring.

OK I can use the mpg a little now. I'm implementing RSA encryption. I'm still having a problem with factorization. I want to make a function for factoring.

It's gmp not mpg. Does anyone have a good factoring algorithm or code at least. Mine's slow as hell for big numbers.

I'm replying to myself again lol, but just in case anyone's interested, I have a program here to find a factor of a number. It follows the Pollard rho algorithm. It seems to work for the most part. There are some problems. It has the error, Floating exception (core dumped), when a prime number is entered. But what I can't figure out is why it also has that error for some numbers that should factor, such as 9, 8, 15, 16, and 99.

#include <iostream>
#include <math.h>
using namespace std;

void factor(int n);
int gcd(int num1, int num2 );

int main()
{
  int n;
  cout<<"enter number to factor: ";
  cin>>n;
  factor(n);
  return 0;
}


void factor(int n)
{
  int g = 1;
  int a = 2;
  int b = 2;

  int count = 10000000;

  while(g == 1 && g != n)
  {
    a = (a*a + 2) % n;
    b = (b*b + 2) % n;
    b = (b*b + 2) % n;

    g = gcd(abs(b-a), n);

    ct--;
  }
  cout<<"count: "<<10000000-ct<<endl;
  cout<<"factor: "<<g<<endl;
}


int gcd(int num1, int num2 )
{
        int remainder = num2 % num1;
        if ( remainder != 0 )
                return gcd( remainder,num1 );

        return num1;
}

If someone knows about gmp, I'm still not sure how to put that in use. I wanna work with some 40 digit numbers here. (I know I'm using int up there)

# include <iostream>
using namespace std;
int main ()
{
	int n;
	cout<<"enter the number:";
	cin>>n;
	cout<<"factors are:";
	for(int i=1;i<=n;i++)
	{
		if (n%i==0)
		cout<<i<<endl;
	}
	int q;
	cin>>q;
	return 0;
}

I hope this works

Comments
After 5 years I doubt he will care.
This article has been dead for over six months. Start a new discussion instead.