18 template <
int p,
class T=
int>
29 Z(TT n){ rep=(
long int)n%p;
32 Z(
double n): rep((((unsigned)n%p)+p)%p){}
33 Z(
char * s):rep(((atoll(s)%p)+p)%p){}
56 tmp *= z.
rep; tmp %= p; rep=tmp;
75 if (res.
rep<0) res.
rep+=(T)p;
78 template<
typename Typ>
102 {
Z<p,T> res; res.
rep=(rep*b.rep)%p;
return res;}
105 {
Z<p,T> res; res.
rep=(rep*b)%p;
return res;}
109 {
return (
Z<p,T>(rep)/=b);}
113 template<
int p,
typename T>
115 std::ostream & operator<<(std::ostream& os, const Z<p,T> & z)
116 {
return (os << z.rep);}
122 template<
int p,
typename T>
125 {
return (is >> z.
rep);}
137 template <
int p,
typename T>
148 inverse=(T*)
malloc(p*
sizeof(T));
159 if(z==0){std::cout<<
"division by zero"<<std::endl;exit(-10);}
160 if(inverse[(
int)z.
rep]==-1)
164 for(inversez=0;((inversez*z.
rep) % p)!=1;inversez++);
168 for(;comp*2<p,comp*=2)
169 expon[2*comp]=(expon[comp]*expon[comp]) %p;
170 inversez=expon[comp];
171 for(
int total=comp;total<p-2;total+=comp)
173 for(;comp+total>p-2;comp/=2);
174 inversez=(inversez * expon[comp]) %p;
177 inverse[(int)z.
rep]=inversez;
179 rep *=inverse[(int)z.
rep];
180 rep =((
long int) rep) % p;
189 if(tmp>=32051) tmp-=32051;
199 tmp=(tmp+b.
rep);
if (tmp>32051) tmp-=32051;
206 {
int tmp=rep; rep=(
short int)((tmp * z.
rep)% 32051);
return *
this;}
220 static int *inverse=NULL;
227 inverse=(
int*)
malloc(32051*
sizeof(
int));
229 cout<<
"je malloc tout ca"<<endl;
230 for(
int i=0;
i<32051;
i++)
240 if(z==0){std::cout<<
"division by zero"<<endl;exit(-10);}
241 if(inverse[(
int)z.
rep]==-1)
245 for(inversez=0;((inversez*z.
rep % 32051)!=1);inversez++);
249 for(;comp*2<32051,comp*=2)
250 expon[2*comp]=(expon[comp]*expon[comp]) %32051;
251 inversez=expon[comp];
252 for(
int total=comp;total<32051-2;total+=comp)
254 for(;comp+total>32051-2;comp/=2);
255 inversez=(inversez * expon[comp]) %32051;
258 inverse[z.
rep]=inversez;
260 flag=rep *inverse[z.
rep];
269 template <
int p,
class T>
274 if(n <0){e=1/
a;m=-n;}
else {e=
a;m=n;}
277 m -=1; m/=2; r*=e; e*=e;
std::istream & operator>>(std::istream &is, Z< p, T > &z)
Definition: Zp.hpp:124
Z< p, T > & operator=(const Z< p, T > &z)
Definition: Zp.hpp:36
Z< p, T > & operator-=(const Z< p, T > z)
Definition: Zp.hpp:46
long flag
Definition: alp_f2c.H:52
void inverse(int *&, int)
Z(const Z< p, T > &z)
Definition: Zp.hpp:34
Z< p, T > operator/(const Z< p, T > &b) const
Definition: Zp.hpp:108
bool operator!=(const Z< p, T > &z) const
Definition: Zp.hpp:61
bool operator>(const Typ &b) const
Definition: Zp.hpp:79
Z< p, T > operator-(const Z< p, T > &b) const
Definition: Zp.hpp:71
Z< p, T > & operator+=(const Z< p, T > z)
Definition: Zp.hpp:38
bool operator==(const Z< p, T > &z) const
Definition: Zp.hpp:60
Z< p, T > & operator/=(const Z< p, T > z)
Definition: Zp.C:19
Z< p, T > & operator*=(const Z< p, T > z)
Definition: Zp.hpp:53
MSKint32t MSKint32t MSKint32t i
Definition: mosek.h:2278
Z(char *s)
Definition: Zp.hpp:33
Z< p, T > operator^(const Z< p, T > a, const int n)
Fast binary exponentiation.
Definition: Zp.hpp:270
Z< p, T > operator*(const int b) const
Definition: Zp.hpp:104
MSKrescodee r
Definition: mosek.h:2321
Z< p, T > operator+(const Z< p, T > &b) const
Definition: Zp.hpp:63
MSKstreamtypee MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t MSKint32t a
Definition: mosek.h:3833
T rep
Definition: Zp.hpp:25
Z< p, T > operator*(const Z< p, T > &b) const
Definition: Zp.hpp:84
Z(double n)
Definition: Zp.hpp:32
Z(TT n)
Definition: Zp.hpp:29