Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C++ - computing the Legendre's symbol

Name: Anonymous 2009-10-21 10:56

    I need help with computing the Legendre's symbol. I need it for my quadratic sieve to work.

    Wiki says I should do it like that Symbol(a,p)=a^((p-1)/2) mod p , unfortunately, it doesn't seem to work in C++. I'm writing my program for a coding competition so don't link me to any libraries - I can't use them.

    double Legendre(double a, double p)
    {

    return double(int(pow(a,((p-1)/2)))%int(p));

    }

    tl,dr How do I quickly check if Q is a Quadratic residue mod P?

Name: Anonymous 2009-10-21 11:07

Name: Anonymous 2009-10-21 11:10

p has to be prime because of oilers theorem

Name: Anonymous 2009-10-21 11:57

>>1
is defined for integers a and positive odd primes p

Why the hell is your function taking in doubles? Also >>3

Name: Anonymous 2009-10-21 12:46

>>1
Sorry, C++ can't do this.  You must use Haskell.

Name: Anonymous 2009-10-21 16:22

Too many parentheses.

Name: Anonymous 2009-10-21 20:17

>>3
Euler's

Name: Anonymous 2009-10-21 22:42

>>7
youler's

Name: Anonymous 2009-10-22 0:35

I've started having fun writing classes to reduce and evaluate Jacobi symbols. It's nowhere near competition efficient, but I'll let you know what I find. Also, it's in Java.

Does linking to libraries exclude the core libraries? Because fucking stupid if it does, but just checking.

Name: Anonymous 2009-10-22 0:46

oh, I'm retarded.
http://en.wikipedia.org/wiki/Jacobi_symbol#Calculating_the_Jacobi_symbol
that was much better a plan.
and it solves your problem too.

Name: Anonymous 2009-10-22 0:57

>>9,10

IHBT

Name: Anonymous 2009-10-22 1:17

>>10
efficient[3]

Name: Anonymous 2009-10-22 10:48

>>8
What about my being ler's?

Name: Anonymous 2010-12-25 3:55

Name: Anonymous 2011-02-03 4:12


Don't change these.
Name: Email:
Entire Thread Thread List