【杂项】随机化
一个RAND()函数罢了
#include <stdio.h>
#include <time.h>
#include <cmath>
#include <stdlib.h>
//Brand;
namespace BIKUrand {
template<typename Tec>
Tec Bquick_pow(Tec _a,Tec _n,Tec _p) {
#define ull unsigned long long
ull Bres = 1;
ull _ia = _a, _in = _n, _ip = _p;
while(_in) {
if(_in&1) Bres = Bres*_ia%_ip;
_ia = _ia*_ia%_ip;
_in >>= 1;
}
#undef ull
return (Tec)Bres;
}
template<typename Tec>
Tec Bquick_pow(Tec _a,Tec _n) {
#define ull unsigned long long
ull Bres = 1;
ull _ia = _a, _in = _n;
while(_in) {
if(_in&1) Bres = Bres*_ia;
_ia = _ia*_ia;
_in >>= 1;
}
#undef ull
return (Tec)Bres;
}
bool Bcheck = false;
void Bbegin() {
if(Bcheck) return;
Bcheck = true;
srand(time(0));
}
int Bcount;
template<typename Tec>
Tec B01make(Tec _aim) {
if(rand()%(Tec)(sqrt(_aim)*sqrt(sqrt(_aim))*sqrt(sqrt(sqrt(_aim)))) == 0)
return rand()&1;
else
return Bquick_pow((_aim-7),(Tec)rand(),_aim);
}
int Brand() {
if(!Bcheck)
Bbegin();
unsigned int Bbase = rand();
unsigned int Bup = rand();
return Bquick_pow(Bbase,Bup);
}
int Bbinrand() {
if(!Bcheck)
Bbegin();
int Bres = 0;
int Bcnt = 0;
while(Bcnt < 8*sizeof(int)) {
Bres += (rand()%4)*(1<<Bcnt);
Bcnt += 2;
}
return Bres;
}
template<typename Tec>
Tec Brand(Tec _limit) {
if(!Bcheck)
Bbegin();
Tec Bbase = rand();
Tec Bup = rand();
Tec Bres = Bquick_pow(Bbase,Bup,_limit);
return (Bres > 1) ? Bres : B01make(_limit);
}
template<typename Tec>
Tec Brand(Tec _left,Tec _right) {
return Brand(_right-_left+1)+_left;
}
} using namespace BIKUrand;