12,691,948 members (30,230 online)
alternative version

7.1K views
1 bookmarked
Posted

# Legendre Symbol (C# code)

, 22 Apr 2012 CPOL
 Rate this:
Culculating Legendre Symbol

## Introduction

In number theory, the Legendre symbol is a multiplicative function with values 1, -1, 0 that is a quadratic character modulo a prime number p: its value on a (nonzero) quadratic residue mod p is 1 and on a quadratic non-residue is -1.

The Legendre symbol was introduced by Adrien-Marie Legendre in 1798[1] in the course of proving the law of quadratic reciprocity. Its generalizations include the Jacobi symbol and Dirichlet characters of higher order. The notational convenience of the Legendre symbol inspired introduction of several other "symbols" used in algebraic number theory, such as the Hilbert symbol and the Artin symbol.

## Using the Code

```//Calculating Legandre symbol
public int L(int a, int p)
{
if (a == 1)
{
return 1;
}
if (a % 2 == 0)
{
return Convert.ToInt32(L(a / 2, p) * Math.Pow(-1, (p * p - 1) / 8));
}
if ((a % 2 != 0) && (a != 1))
{
return Convert.ToInt32(L(p % a, a) * Math.Pow(-1, (a - 1) * (p - 1) / 4));
}
return 0;
} ```

## Share

 Software Developer (Junior) Ukraine
No Biography provided

## You may also be interested in...

 Pro Pro

 First Prev Next
 [My vote of 2] This has problems... Matt T Heffron23-Apr-12 13:23 Matt T Heffron 23-Apr-12 13:23
 Please submit as a tip! Dave Kerr19-Apr-12 23:24 Dave Kerr 19-Apr-12 23:24
 Re: Please submit as a tip! Poisson_PS20-Apr-12 10:19 Poisson_PS 20-Apr-12 10:19
 Not an article Sridhar Patnayak19-Apr-12 21:05 Sridhar Patnayak 19-Apr-12 21:05
 Agree with others Mika Wendelius19-Apr-12 11:40 Mika Wendelius 19-Apr-12 11:40
 Not enough here. mark merrens19-Apr-12 10:57 mark merrens 19-Apr-12 10:57
 to short for an article Leonardo Paneque19-Apr-12 10:37 Leonardo Paneque 19-Apr-12 10:37
 Last Visit: 31-Dec-99 19:00     Last Update: 17-Jan-17 13:52 Refresh 1