64,646
社区成员
发帖
与我相关
我的任务
分享
struct deref_less;
class TGMP;
typedef set<TGMP*, deref_less> TGMPset;
class TGMP
{
public:
int data;
TGMP(int d):data(d){}
TGMPset func();
};
bool operator<(const TGMP x, const TGMP y)
{
return x.data<y.data?true:false;
}
struct deref_less
{
bool operator()(TGMP* p, TGMP* q) const
{
return *p<*q;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
TGMP x(0);
TGMPset s=x.func();
// 清理
for(TGMPset::iterator i=s.begin();i!=s.end();++i) delete *i;
s.clear();
return 0;
}
TGMPset TGMP::func()
{
TGMPset s;
TGMP *t1=new TGMP(4);
TGMP *t2=new TGMP(5);
TGMP *t3=new TGMP(4);
if(!s.insert(t1).second) delete t1;
if(!s.insert(t2).second) delete t2;
if(!s.insert(t3).second) delete t3;
return s;
}
[Quote=引用 13 楼 worldcreater 的回复:]
set<TGMP> TGMP::pollardRHO(const unsigned long int o) {
set<TGMP> r;
TGMP n, i, x, y, k, d;
n = o;
i = 1;
x = o - 1; //x = TGMP::urandomm(o-1);
y = x;
k = 2;
//一旦到達 x[i] 满足當 j<i 時 x[i]=x[j] 則已處在一個循環中
while (true) {
i = i + 1;
x = (x * x - 1) % n; //x[i] = (x[i-1]^2 - 1) % n
d = TGMP::gcd(y-x, n);
if ((d!=1)&&(d!=n)) {
cout << d.toString() << ", ";
r.insert(d); /////////只在这里用到 返回值
// break;
// cout << "n" << n.toString() << ", i" << i.toString() << ", x" << x.toString() << ", y" << y.toString() << ", k" << k.toString() << ", d" << d.toString() << endl;
} else if (i==k) {
y = x;
k = k * 2;
}
if (i>o) break;
}
cout << endl;
return r; //以及这返回 r
}
class TGMP
{
public:
int data;
TGMP(int d):data(d){}
};
bool operator<(const TGMP x, const TGMP y)
{
return x.data<y.data?true:false;
}
struct deref_less
{
bool operator()(TGMP* p, TGMP* q) const
{
return *p<*q;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
typedef set<TGMP*, deref_less> TGMPset;
TGMPset s;
TGMP *t1=new TGMP(4);
TGMP *t2=new TGMP(5);
TGMP *t3=new TGMP(4);
if(!s.insert(t1).second) delete t1;
if(!s.insert(t2).second) delete t2;
if(!s.insert(t3).second) delete t3;
// ...
// 清理
for(TGMPset::iterator i=s.begin();i!=s.end();++i) delete *i;
s.clear();
return 0;
}
[Quote=引用 10 楼 worldcreater 的回复:]struct deref_less
{
bool operator()(TGMP* p, TGMP* q) const
{
return *p<*q;
}
};
set<TGMP*, deref_less> r;
[Quote=引用 8 楼 worldcreater 的回复:] set<TGMP*, less<TGMP*> > r;
r = TGMP::pollardRHO(60);
cout << r.size() << endl;
set<TGMP*, less<TGMP*> >::iterator it = r.begin();
while (it != r.end()) {
cout << ((TGMP*)*it)->toString() << " ";
it++;
}
cout << endl;
TGMP* t = new TGMP();
*t = d;
r.insert(*t); ///返回値設成 set<TGMP> 時的
struct less_tgmp; //使用 typedef struct less_tgmp; 也一样
class TGMP
{
... ....
static set<TGMP*, less_tgmp> pollardRHOx(const unsigned long int);
protected:
private:
mpz_t value;
};
struct less_tgmp {
bool operator()(TGMP* p, TGMP* q) const {
return *p<*q;
}
};
set<TGMP*, less_tgmp> TGMP::pollardRHOx(const unsigned long int o) {
set<TGMP*, less_tgmp> r;
TGMP n, i, x, y, k, d;
n = o;
i = 1;
x = o - 1; //x = TGMP::urandomm(o-1);
y = x;
k = 2;
//一旦到達 x[i] 满足當 j<i 時 x[i]=x[j] 則已處在一個循環中
while (true) {
i = i + 1;
x = (x * x - 1) % n; //x[i] = (x[i-1]^2 - 1) % n
d = TGMP::gcd(y-x, n);
if ((d!=1)&&(d!=n)) {
cout << d.toString() << ", ";
TGMP* t = new TGMP();
*t = d;
r.insert(t);
// break;
// cout << "n" << n.toString() << ", i" << i.toString() << ", x" << x.toString() << ", y" << y.toString() << ", k" << k.toString() << ", d" << d.toString() << endl;
} else if (i==k) {
y = x;
k = k * 2;
}
if (i>o) break;
}
// cout << endl;
return r;
}
struct less_tgmp;
class TGMP;
typedef set<TGMP*, less_tgmp> TGMPset;
class TGMP
{
public:
int data;
TGMP(int d):data(d){}
static TGMPset func();
};
bool operator<(const TGMP x, const TGMP y)
{
return x.data<y.data?true:false;
}
struct less_tgmp
{
bool operator()(TGMP* p, TGMP* q) const
{
return *p<*q;
}
};
int _tmain(int argc, _TCHAR* argv[])
{
TGMPset s=TGMP::func();
// 清理
for(TGMPset::iterator i=s.begin();i!=s.end();++i) delete *i;
s.clear();
return 0;
}
TGMPset TGMP::func()
{
TGMPset s;
TGMP *t1=new TGMP(4);
TGMP *t2=new TGMP(5);
TGMP *t3=new TGMP(4);
if(!s.insert(t1).second) delete t1;
if(!s.insert(t2).second) delete t2;
if(!s.insert(t3).second) delete t3;
return s;
}
[Quote=引用 13 楼 worldcreater 的回复:]