MCPcopy Create free account
hub / github.com/SuprDewd/CompetitiveProgramming / leg

Function leg

code/mathematics/tonelli_shanks.cpp:2–5  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include "mod_pow.cpp"
2ll leg(ll a, ll p) {
3 if (a % p == 0) return 0;
4 if (p == 2) return 1;
5 return mod_pow(a, (p-1)/2, p) == 1 ? 1 : -1; }
6ll tonelli_shanks(ll n, ll p) {
7 assert(leg(n,p) == 1);
8 if (p == 2) return 1;

Callers 2

tonelli_shanksFunction · 0.85
testFunction · 0.85

Calls 1

mod_powFunction · 0.85

Tested by 1

testFunction · 0.68