int main()
{
	ull i,x,s,m;
	ull f41[10];
	f41[0] =1;
	for(i=1;i<=9;i++)
		f41[i] = f41[i-1]*41;
	fact[0] = fact2[0] = 1;
	for(i=1;i<=max;i++)
		fact[i] = ( ( ( fact[i-1] * (4*i-2) ) % mod4 ) * minv(i,mod4) ) % mod4;
	for(i=1;i<=2*max;i++)
	{
		x = i;
		while(!(x%41))
			x/=41;
		fact2[i] = (fact2[i-1]*x)%mod6;
	}
	ncr[0] = 1;
	for(i=1;i<=max;i++)
	{
		s = minv(fact2[i],mod6);
		s = (s*s)%mod6;
		x = (fact2[2*i]*s)%mod6;
		m = pow_fact(2*i) - 2*pow_fact(i);
		x = (x*f41[m])%mod6;
		ncr[i] = crt(fact[i],x);
	}
	return 0;
}
Beispiel #2
0
/**
 * Recombine les racines modulo mod1 et mod2 pour trouver les racines finales.
 * rac_modi[0]contient les valeurs en x des racines et rac_modi[1] celles en y. 
 * @param rac_mod1 tableau des couples (x, y) de racines modulo mod1
 * @param rac_mod2 tableau des couples (x, y) de racines modulo mod2
 * @param nb1 nombre de racines (x, y) dans rac_mod1
 * @param nb2 nombre de racines (x, y) dans rac_mod2 
 */
void find_roots(mpz_t *rac_mod1[2], mpz_t *rac_mod2[2], int nb1, int nb2,  mpz_t mod1, mpz_t mod2, mpz_t **PY, mpz_t **QY, int *degres_PY, int *degresQY, int deg_P, int deg_Q, mpz_t mod){
  
  int i, j, nb_racines=0;
  mpz_t rx, ry, isroot;
  mpz_inits(rx, ry, isroot, NULL);

  for(i=0; i<nb1; i++){
    for(j=0; j<nb2; j++){

      /* crt sur la i eme racine mod1 et la j eme mod2 */ 
      crt(rx, rac_mod1[0][i], rac_mod2[0][j], mod1, mod2);
      crt(ry, rac_mod1[1][i], rac_mod2[1][j], mod1, mod2);

      /* on evalue en le resultat (rx, ry) trouve */
      eval_bivXY(isroot, rx, ry, PY, degres_PY, deg_P, mod);

      /* on teste si le resultat est bien racine */
      if (!mpz_cmp_si(isroot, 0)){
	printf("(%ld, %ld) est racine\n", mpz_get_si(rx), mpz_get_si(ry));
	nb_racines++;
      }
    }
  }
  
  printf("%d racines au total\n", nb_racines);
  
  
  
}
Beispiel #3
0
void PAlgebraModDerived<type>::embedInSlots(RX& H, const vector<RX>& alphas,
        const MappingData<type>& mappingData) const
{
    long nSlots = zMStar.getNSlots();
    assert(lsize(alphas) == nSlots);

    for (long i = 0; i < nSlots; i++) assert(deg(alphas[i]) < mappingData.degG);

    vector<RX> crt(nSlots); // alloate space for CRT components

    // The i'th CRT component is (H mod F_t) = alphas[i](maps[i]) mod F_t,
    // where with t=T[i].

    if (IsX(mappingData.G)) {
        // special case...no need for CompMod, which is
        // is not optimized for zero

        for (long i=0; i<nSlots; i++)   // crt[i] = alpha(maps[i]) mod Ft
            crt[i] = ConstTerm(alphas[i]);
    }
    else {
        // general case...

        for (long i=0; i<nSlots; i++)   // crt[i] = alpha(maps[i]) mod Ft
            CompMod(crt[i], alphas[i], mappingData.maps[i], factors[i]);
    }

    CRT_reconstruct(H,crt); // interpolate to get p
}
Beispiel #4
0
HRESULT tabular_rowset::Execute(DBPARAMS * /*pParams*/, DBROWCOUNT* pcRowsAffected)
{
	IExtendCommand* pIExtCommand = NULL;
	HRESULT hr = m_spUnkSite->QueryInterface( __uuidof( IExtendCommand ), ( void**) &pIExtCommand );
	
	if FAILED( hr ) return hr;

	pIExtCommand->GetConnectionHandler( (void**)&mConnectionHandler );

	pIExtCommand->Release();

	const int row_count = mConnectionHandler->access_tab_data().row_count();
	const int data_size = mConnectionHandler->access_tab_data().data_size();

	if ( (NULL != pcRowsAffected) && (NULL != mConnectionHandler) )
	{
		*pcRowsAffected = row_count-1;
	}

	for ( int i = 1; i < row_count; ++i )
	{
		tabular_row_data crt(data_size);
		mConnectionHandler->access_tab_data().load_at( i, (wchar_t*)&crt );
		m_rgRowData.Add( crt );
	}



	return S_OK;
}
Beispiel #5
0
void PAlgebraModDerived<type>::embedInAllSlots(RX& H, const RX& alpha, 
                                            const MappingData<type>& mappingData) const
{
  if (isDryRun()) {
    H = RX::zero();
    return;
  }
  FHE_TIMER_START;
  long nSlots = zMStar.getNSlots();

  vector<RX> crt(nSlots); // alloate space for CRT components

  // The i'th CRT component is (H mod F_t) = alpha(maps[i]) mod F_t,
  // where with t=T[i].

  
  if (IsX(mappingData.G) || deg(alpha) <= 0) {
    // special case...no need for CompMod, which is
    // is not optimized for this case

    for (long i=0; i<nSlots; i++)   // crt[i] = alpha(maps[i]) mod Ft
      crt[i] = ConstTerm(alpha);
  }
  else {
    // general case...

    for (long i=0; i<nSlots; i++)   // crt[i] = alpha(maps[i]) mod Ft
      CompMod(crt[i], alpha, mappingData.maps[i], factors[i]);
  }

  CRT_reconstruct(H,crt); // interpolate to get H
  FHE_TIMER_STOP;
}
Beispiel #6
0
void pollard(big id,big dl)
{
    int i;
    long iter;
    big_chinese bc;
    big w,Q,R,m,n,q;
    char stack_mem[mr_big_reserve(6,50)];
    memset(stack_mem,0,mr_big_reserve(6,50));

    w=mirvar_mem(stack_mem,0);
    Q=mirvar_mem(stack_mem,1);
    R=mirvar_mem(stack_mem,2);
    m=mirvar_mem(stack_mem,3);
    n=mirvar_mem(stack_mem,4);
    q=mirvar_mem(stack_mem,5);

    copy(id,q);
    crt_init(&bc,np,pp);
    for (i=0;i<np;i++)
    { /* accumulate solutions for each pp */
        copy(p1,w);
        divide(w,pp[i],w);
        powmod(q,w,p,Q);
        powltr(PROOT,w,p,R);
        copy(pp[i],order);
        iter=rho(Q,R,m,n);
        xgcd(m,order,w,w,w);

        mad(w,n,n,order,order,rem[i]);
        printf("%9ld iterations needed\n",iter);
    }
    crt(&bc,rem,dl);  /* apply chinese remainder thereom */
    crt_end(&bc);
}
Beispiel #7
0
Big Crt::eval(Big *u)
{           
    Big x;
    big *b=(big *)mr_alloc(bc.NP,sizeof(big));
    for (int i=0;i<bc.NP;i++) b[i]=u[i].getbig();
    crt(&bc,b,x.getbig());
    mr_free(b); 
    return x;
}
Beispiel #8
0
void httplus::App::load(kul::hash::map::S2T<std::shared_ptr<http::Server>>& http,
            kul::hash::map::S2T<std::shared_ptr<https::Server>>& https, Sites& sites) throw(httplus::Exception){

    std::shared_ptr<http::Conf> defHttp;
    if(config.root()["http"])
        for(const YAML::Node& c : config.root()["http"]){
            if(defHttp && !c["host"]) KEXCEPTION("Only one http allowed without 'host' parameter");
            const std::string& port(c["port"] ? c["port"].Scalar() : "80");
            kul::Dir d(c["root"].Scalar());
            if(!d) KEXCEPTION("Directory does not exist: " + c["root"].Scalar());
            kul::Dir p("pub", d);
            if(!p && !p.mk()) KEXCEPTION("Invalid access on directory: " + d.real());
            http::Server* ser = {0};
            std::string home(c["home"] ? c["home"].Scalar() : "");
            const std::string txt(c["text"] ? c["text"].Scalar() : "");
            if(!c["host"]){
                defHttp = std::make_shared<http::Conf>(c["root"].Scalar(), home, txt);
            }else if(sites.count(std::to_string(std::hash<std::string>()(d.real())))){
                const Pages& pages((*sites.find(std::to_string(std::hash<std::string>()(d.real())))).second);
                http.insert(port, std::make_shared<http::Server>(kul::String::UINT16(port), pages));
                ser = http[port].get();
                ser->confs.insert(c["host"].Scalar(), std::make_shared<http::Conf>(c["root"].Scalar(), home, txt));
            }else
                KERR << "WARN: NO GENERATORS FOR HTTP ROOT: " << d;

        }
    for(const auto& p : http) p.second->def = defHttp;
    if(config.root()["https"])
        for(const YAML::Node& c : config.root()["https"]){
            kul::Dir d(c["root"].Scalar());
            if(!d) KEXCEPTION("Directory does not exist: " + c["root"].Scalar());
            kul::Dir p("pub", d);
            if(!p && !p.mk()) KEXCEPTION("Invalid access on directory: " + d.real());
            kul::File crt(c["crt"].Scalar());
            kul::File key(c["key"].Scalar());
            if(!crt) KEXCEPTION("File does not exist: " + crt.full());
            if(!key) KEXCEPTION("File does not exist: " + key.full());
            https::Server* ser = {0};
            const std::string& port(c["port"] ? c["port"].Scalar() : "443");
            const std::string hsh(std::to_string(std::hash<std::string>()(d.real())));
            if(!sites.count(hsh)) {
                KERR << "WARN: NO GENERATORS FOR HTTPS ROOT: " << d;
                continue; 
            }
            const Pages& pages((*sites.find(hsh)).second);
            std::string ssls(c["ssls"] ? c["ssls"].Scalar() 
                : config.root()["ssls"] ? config.root()["ssls"].Scalar() : "");
            https.insert(port, std::make_shared<https::Server>(kul::String::UINT16(port), pages, crt, key, ssls));
            ser = https[port].get();
            ser->init();
            if(c["chain"]) ser->setChain(c["chain"].Scalar());
            std::string home(c["home"] ? c["home"].Scalar() : "");
            const std::string txt(c["text"] ? c["text"].Scalar() : "");
            ser->confs.insert(c["host"].Scalar(), std::make_shared<http::Conf>(c["root"].Scalar(), home, txt));
        }
}
Beispiel #9
0
 int fd(int l,int r,int k) {
     int da=0;
     if(bj!=-1) {
         push();
         crt();
     }
     for(int i=l; i<=r; i++) {
         da+=(a[i%cs]==k);
     }
     return da;
 }
Beispiel #10
0
static void
dec(int not)
{
	if (not)
		inval();
	ts.c_cc[VERASE] = '\177';
	ts.c_cc[VKILL] = '\25';
	ts.c_cc[VINTR] = '\3';
	ts.c_iflag &= ~(tcflag_t)IXANY;
	crt(not);
}
int main()
{
	long i,j,k,h,n,m,mx;
	bool flag;
	scanf("%d",&n);
	while (n>0)
	{
		mx=0;
		memset(map,2,sizeof(map));
		for (i=1;i<=n;i++)
			for (j=1;j<=n;j++)
				scanf("%d",&map[i][j]);
		for (i=1;i<=n;i++)
			for (j=1;j<=n;j++)
			{
				flag=false;
				for (k=j;k<=n;k++)
				{
					if (map[i][k]!=1) 
						break;
				}
				if (k==j) continue;
				for (h=k+1;h<=2*k-j;h++)
					if (map[i][h]!=1)
					{
						flag=true;
						break;
					}
				if (flag) continue;
				m=(k-j)*2+1;
				crt(m);
				for (k=2;k<=m;k++)
				{
					for (h=1;h<=m;h++)
						if (map[i+k-1][j+h-1]!=tm[k][h])
						{
							flag=true;
							break;
						}
					if (flag) break;
				}
				if (flag) break;
				if (m>mx) mx=m;
			}
		if (n>0) printf("%d\n",mx);
		else printf("No solution");
		scanf("%d",&n);
	}
	return 0;
}
Beispiel #12
0
void PAlgebraModTmpl<RX,vec_RX,RXM>::embedInAllSlots(RX& p, const RX& alpha,
						 const vector<RX>& maps) const
{
  unsigned nSlots = zmStar.NSlots();
  if (nSlots==0 || maps.size()!=nSlots) { p=RX::zero(); return; }
  vector<RX> crt(nSlots); // alloate space for CRT components

  // The i'th CRT component is (p mod F_t) = alpha(maps[i]) mod F_t,
  // where with t=T[i].

  for (unsigned i=0; i<nSlots; i++)   // crt[i] = alpha(maps[i]) mod Ft
    CompMod(crt[i], alpha, maps[i], factors[i]);

  CRT_reconstruct(p,crt); // interpolate to get p
}
void crt(long p,long f,long m,long s)
{
	long i;
	if ((f+p)>n) return;
	if (p==0)
	{
		nn[0]++;
		nn[nn[0]]=m;
		ss[m]=s;
	}
	p--;
	for (i=f;i<n;i++)
	{
		crt(p,i+1,m+(1<<i),s+mir[i+1]);
	}
}
Beispiel #14
0
void PAlgebraModDerived<type>::embedInSlots(RX& H, const vector<RX>& alphas, 
                                         const MappingData<type>& mappingData) const
{
  if (isDryRun()) {
    H = RX::zero();
    return;
  }
  FHE_TIMER_START;

  long nSlots = zMStar.getNSlots();
  assert(lsize(alphas) == nSlots);

  for (long i = 0; i < nSlots; i++) assert(deg(alphas[i]) < mappingData.degG); 
 
  vector<RX> crt(nSlots); // alloate space for CRT components

  // The i'th CRT component is (H mod F_t) = alphas[i](maps[i]) mod F_t,
  // where with t=T[i].

  if (IsX(mappingData.G)) {
    // special case...no need for CompMod, which is
    // is not optimized for this case

    for (long i=0; i<nSlots; i++)   // crt[i] = alpha(maps[i]) mod Ft
      crt[i] = ConstTerm(alphas[i]);
  }
  else {
    // general case...still try to avoid CompMod when possible,
    // which is the common case for encoding masks

    for (long i=0; i<nSlots; i++) {   // crt[i] = alpha(maps[i]) mod Ft
      if (deg(alphas[i]) <= 0) 
        crt[i] = alphas[i];
      else
        CompMod(crt[i], alphas[i], mappingData.maps[i], factors[i]);
    }
  }

  CRT_reconstruct(H,crt); // interpolate to get p

  FHE_TIMER_STOP;
}
void freeglut_application::motion_(int x, int y) {
    screen_pos_t crt(x, y);
    if ((left_down_ || right_down_ || middle_down_) && ((crt - drag_start_).template lpNorm<1>() > 2)) {
        if (!dragging_) {
            if (left_down_) drag_start_left_(drag_start_);
            if (right_down_) drag_start_right_(drag_start_);
            if (middle_down_) drag_start_middle_(drag_start_);
        }
        dragging_ = true;
    }

    if (dragging_) {
        if (left_down_) drag_left_(crt, crt - last_pos_);
        if (right_down_) drag_right_(crt, crt - last_pos_);
        if (middle_down_) drag_middle_(crt, crt - last_pos_);
    } else {
        mouse_move_(crt, crt - last_pos_);
    }

    last_pos_ = crt;
}
int main()
{
	ull i,x,s,m;
	ull f41[10];
	f41[0] = 1;
	for(i=1;i<=9;i++)
		f41[i] = f41[i-1]*41;
	fact[0] = fact2[0] = 1;
	for(i=1;i<=max+5;i++)
		fact[i] = ( ( ( fact[i-1] * (4*i-2) ) % mod4 ) * minv(i,mod4) ) % mod4;
	for(i=1;i<=2*max+5;i++)
	{
		x = i;
		while(!(x%41))
			x/=41;
		fact2[i] = (fact2[i-1]*x)%mod6;
	}
	int t,a,b,n=79981;
	for(a=0;a<100;a++)
		for(b=0;b<100;b++)
			{
				s = minv(fact2[n],mod6);
				s = (s*s)%mod6;
				x = (fact2[2*n]*s)%mod6;
				m = pow_fact(2*n) - 2*pow_fact(n);
				x = x*f41[m];
				ull y = crt(fact[n],x%mod6);
				if(n==0)
					y = 1;
				if (y==0)
					y = mod3;
				ull y1 = power(b,y,mod2);
				if(b==0)
					y1 = 0;
				ull z = power(a,y1,mod1);
				printf("%lld\n",z);
			}
	return 0;
}
void freeglut_application::mouse_(int button, int state, int x, int y) {
    screen_pos_t crt(x, y);
    if (state == GLUT_DOWN) {
        switch (button) {
            case GLUT_LEFT_BUTTON:    drag_start_ = crt; left_down_ = true; break;
            case GLUT_RIGHT_BUTTON:   drag_start_ = crt; right_down_ = true; break;
            case GLUT_MIDDLE_BUTTON:  drag_start_ = crt; middle_down_ = true; break;
            case 3: scroll_(1); break;
            case 4: scroll_(-1); break;
        }
    } else {
        if (button == GLUT_LEFT_BUTTON) {
            left_down_ = false;
            if (dragging_) {
                drag_stop_left_(drag_start_, crt);
                dragging_ = false;
            } else {
                click_left_(drag_start_);
            }
        } else if (button == GLUT_RIGHT_BUTTON) {
            right_down_ = false;
            if (dragging_) {
                drag_stop_right_(drag_start_, crt);
                dragging_ = false;
            } else {
                click_right_(drag_start_);
            }
        } else {
            middle_down_ = false;
            if (dragging_) {
                drag_stop_middle_(drag_start_, crt);
                dragging_ = false;
            } else {
                click_middle_(drag_start_);
            }
        }
    }
}
int main()
{
	long i,j,s;
	memset(dp,1,sizeof(dp));
	dp[0]=0;
	memset(mir,0,sizeof(mir));
	memset(c,0,sizeof(c));
	memset(nn,0,sizeof(nn));
	scanf("%ld",&n);
	s=0;
	for (i=1;i<=n;i++)
	{
		scanf("%ld",&mir[i]);
		s+=mir[i];
	}
	for (i=1;i<=n;i++)
	{
		crt(i,0,0,0);
	}
	c[1]=1+(3<<(n-2));
	c[2]=3+(1<<(n-1));
	c[3]=7;
	for (i=4;i<=n;i++)
	{
		c[i]=c[i-1]<<1;
	}
	nn[0]=0;
	for (i=0;i<(1<<n);i++)
	{
		for (j=1;j<=n;j++)
		{
			dp[nn[i]|c[j]]=mn(dp[nn[i]|c[j]],dp[nn[i]]+s-ss[nn[i]|c[j]]);
		}
	}
	printf("%ld\n",dp[nn[(1<<n)-1]]);
	return 0;
}
Beispiel #19
0
void pollard(big id,big dl)
{
    int i;
    long iter;
    big w,Q,R,m,n,q;
    big_chinese bc;
    w=mirvar(0);
    Q=mirvar(0);
    R=mirvar(0);
    m=mirvar(0);
    n=mirvar(0);
    q=mirvar(0);
    
    copy(id,q);
    crt_init(&bc,np,pp);
    for (i=0;i<np;i++)
    { /* accumulate solutions for each pp */
        copy(p1,w);
        divide(w,pp[i],w);
        powmod(q,w,p,Q);
        powltr(PROOT,w,p,R);
        copy(pp[i],order);
        iter=rho(Q,R,m,n);
        xgcd(m,order,w,w,w);
        mad(w,n,n,order,order,rem[i]);
        printf("%9ld iterations needed\n",iter);
    }
    crt(&bc,rem,dl);  /* apply chinese remainder thereom */
    crt_end(&bc);
    mirkill(q);
    mirkill(n);
    mirkill(m);
    mirkill(R);
    mirkill(Q);
    mirkill(w);
}
long CESdkCtrl::CreateCtrl(CWnd *wnd,SDK_CTRL_TYPE emtype)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());
    emtype_ = emtype;

    //<1>创建初始大小按钮 ,加载图标  

    CString strTitle = _T("eSDKCtrl");

    CRect crt(0,0,150,40);//默认控件按钮的大小
    button_.Create(strTitle,WS_VISIBLE,crt,wnd,ID_BUTTON);
    button_.SetOwner(this);

    //<2>切换按钮的风格为windows7风格
    CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows)); 
    CMFCButton::EnableWindowsTheming();

    if(!IsEspaceInstalled())
    {
        button_.EnableWindow(FALSE);
    }

    return SDK_SUCCESS;
}
Beispiel #21
0
/* Compute analytic dynamics */
void computeAnalyticOutputs(std::map<const std::string, bool> &outs,
    struct PARAMETERS * p) {

  // energy spacing in bulk
  std::complex <double> dE ((p->kBandTop-p->kBandEdge)/(p->Nk-1), 0);
  // bulk-QD coupling
  std::complex <double> Vee (p->Vnobridge[0], 0);
  // rate constant (can be defined also as K/2)
  std::complex <double> K = std::complex <double> (3.1415926535,0)*pow(Vee,2)/dE;
  // time
  std::complex <double> t (0, 0);
  // energy differences
  std::complex <double> wnm (0, 0);
  std::complex <double> wnnp (0, 0);
  std::complex <double> wnpm (0, 0);
  // coefficients
  std::complex <double> cm (0, 0);
  std::complex <double> cn (0, 0);
  std::complex <double> cn_term1 (0, 0);
  std::complex <double> cn_term2 (0, 0);
  std::complex <double> cn_diag (0, 0);
  std::complex <double> cn_offdiag (0, 0);
  double cn_tot;
  // complex numbers are dumb
  std::complex <double> C0 (0.0, 0.0);
  std::complex <double> C1 (1.0, 0.0);
  std::complex <double> NEGC1 (-1.0, 0.0);
  std::complex <double> CI (0.0, 1.0);
  std::complex <double> NEGCI (0.0, -1.0);

  // unpack params a bit
  int Nk = p->Nk;
  int Nc = p->Nc;
  int Ik = p->Ik;
  int Ic = p->Ic;
  int N = p->NEQ;
  double * energies = &(p->energies[0]);
  double * startWfn = &(p->startWfn[0]);

  // Create matrix of energy differences
  std::vector<std::complex <double>> Elr (Nk*Nc, std::complex <double> (0.0, 0.0));
  for (int ii = 0; ii < Nk; ii++) {
    for (int jj = 0; jj < Nc; jj++) {
      // array follows convention that first index is for QC state
      // e.g. Elr[i*Nc + j] = E_{ij}
      Elr[ii*Nc + jj] = std::complex <double> (energies[Ik + ii] - energies[Ic + jj], 0);
    }
  }
#ifdef DEBUG_ANALYTIC
  std::cout << std::endl;
  std::cout << "Energy gaps:" << std::endl;
  for (int ii = 0; ii < Nc*Nk; ii++) {
    std::cout << Elr[ii] << " ";
  }
  std::cout << std::endl;
  std::cout << std::endl;
#endif

  // Create matrix of prefactors for each QC (n) state
  std::complex <double> pref;
  std::vector<std::complex <double>> prefQC (Nk*Nc, std::complex <double> (0.0, 0.0));
  for (int ii = 0; ii < Nk; ii++) {
    // V*c_l/(E_{lr} + i\kappa)
    pref = Vee*(std::complex <double> (startWfn[Ik + ii], startWfn[Ik + N + ii]));
    std::cout << startWfn[Ik + ii] << "," << pref << " ";
    for (int jj = 0; jj < Nc; jj++) {
      prefQC[ii*Nc + jj] = pref/(Elr[ii*Nc + jj] + CI*K);
    }
  }
#ifdef DEBUG_ANALYTIC
  std::cout << std::endl;
  for (int ii = 0; ii < Nc*Nk; ii++) {
    std::cout << prefQC[ii] << " ";
  }
  std::cout << std::endl;
  std::cout << std::endl;
#endif

  // calculate wavefunction coefficients on electron-accepting side over time
  std::vector<std::complex <double>> crt (Nc*p->numOutputSteps, std::complex <double> (0.0, 0.0));

  int timeIndex = 0;
  for (std::complex <double> t = C0; std::real(t) <= p->tout;
       t += std::complex <double> (p->tout/p->numOutputSteps, 0.0), timeIndex++) {
    for (int ii = 0; ii < Nc; ii++) {
      // TODO add bit for multiple state terms
      for (int jj = 0; jj < Nk; jj++) {
	crt[timeIndex*Nc + ii] += prefQC[jj]*(exp(NEGCI*Elr[jj*Nc + ii]*t) - exp(NEGC1*K*t));
      }
    }
  }
  
  // calculate populations on electron-accepting side over time
  std::vector<double> Prt (Nc*p->numOutputSteps, 0.0);
  for (int ii = 0; ii <= p->numOutputSteps; ii++) {
    for (int jj = 0; jj < Nc; jj++) {
      Prt[ii*Nc + jj] = pow(real(crt[ii*Nc + jj]), 2) + pow(imag(crt[ii*Nc + jj]), 2);
    }
  }

  if (isOutput(outs, "analytic_tcprob.out")) {
    std::ofstream output("analytic_tcprob.out");
    for (int ii = 0; ii <= p->numOutputSteps; ii++) {
      output << p->times[ii];
      for (int jj = 0; jj < Nc; jj++) {
	output << " " << Prt[ii*Nc + jj];
	output << " " << real(crt[ii*Nc + jj]) << " " << imag(crt[ii*Nc + jj]);
      }
      output << std::endl;
    }
    output.close();
  }

  return;
}
// Program verifies case l=ell from Theorem 4.
// Reads input from stdin about location of files.
// Format is:
//   prime file
//   prime2 file2
//   ...
// Where prime, prime2,... represent the moduli of file, file2,... .
int main(int argc, char *argv[])
{
   unsigned long int ell, i, n, num, thisprime, numprimes;
   unsigned long int three_to_ell, three_to_ellMinusOne, nbound;
   unsigned long int *a, *m;
   mpz_t answer;
   int items;
   char thisfilename[128];
   FILE **datafiles;

   if( argc < 2 )
   {
      fprintf( stderr, "\nUsage:\n\t%s ell\n", argv[0] );
      fprintf( stderr, "Makes sure that the case l=ell is true for Theorem 4 in\n`Parity of 5-regular and 13-regular Partition Functions'");
      return 1;
   }

   // Parse arguments.
   ell = strtoul(argv[1], NULL, 10);

   // Allocate memory for stuff.
   m = malloc( sizeof(unsigned long) * M_ITEMS );
   a = malloc( sizeof(unsigned long) * M_ITEMS );
   datafiles = malloc( sizeof(FILE *) * M_ITEMS );
   mpz_init(answer);

   // Set up constants.
   three_to_ell = 1;
   three_to_ellMinusOne = 1;

   for( i=0; i < ell; ++i )
      three_to_ell *= 3;
   for( i=0; i < ell-1; ++i )
      three_to_ellMinusOne *= 3;
   nbound = 7*three_to_ellMinusOne + 3;

   // Set up primes and files.
   i = 0;
   while(1)
   {
      items = fscanf( stdin, "%lu %s\n", &thisprime, thisfilename );
      if( items == 2 )
      {
         datafiles[i] = fopen( thisfilename, "r" );
         m[i] = thisprime;
         i++;
      }
      else
         break;
   }

   // Now we know how many primes we're working with.
   numprimes = i;

   for( n=1; n <= nbound; ++n )
   {
      // Set num to number in b_13 fn in thm4.
      num = three_to_ell*n + (5*three_to_ellMinusOne - 1)/2;

      // Set up the a[] array.
      for( i=0; i < numprimes; ++i )
      {
         fseek( datafiles[i], 4L*num, SEEK_SET );
         fread( &a[i], 4, 1, datafiles[i] );
      }

      // Get result from chinese remainder thm.
      crt( answer, a, m, numprimes );

      // If it's not zero mod 3...oh shit.
      if( mpz_mod_ui( answer, answer, (unsigned long)3 ) != 0 )
      {
         printf("Failed case: n=%lu num=%lu b_13(num)=", n, num);
         mpz_out_str(stdout, 10, answer);
         printf("\n");
         fflush(stdout);

         exit(1);
      }
   }

   printf("Yay! Case l=%lu is true!\n", ell);

   // Close all files.
   for( i = 0; i < numprimes; ++i )
      fclose( datafiles[i] );

   // Free all memory.
   free(a);
   free(m);
   free(datafiles);

   return 0;
}
Beispiel #23
0
int main()
{  /*  decode using private key  */
    int i;
    big e,ep[NP],m,ke,kd,p[NP],kp[NP],mn,mx;
    FILE *ifile;
    FILE *ofile;
    char ifname[13],ofname[13];
    BOOL flo;
    big_chinese ch;
    mip=mirsys(100,0);
    for (i=0;i<NP;i++)
    {
        p[i]=mirvar(0);
        ep[i]=mirvar(0);
        kp[i]=mirvar(0);
    }
    e=mirvar(0);
    m=mirvar(0);
    kd=mirvar(0);
    ke=mirvar(0);
    mn=mirvar(0);
    mx=mirvar(0);
    mip->IOBASE=60;
    if ((ifile=fopen("private.key","r"))==NULL)
    {
        printf("Unable to open file private.key\n");
        return 0;
    }
    for (i=0;i<NP;i++)
    {
        cinnum(p[i],ifile);
    }
    fclose(ifile);
 /* generate public and private keys */
    convert(1,ke);
    for (i=0;i<NP;i++)
    {
        multiply(ke,p[i],ke);
    }
    for (i=0;i<NP;i++)
    { /* kp[i]=(2*(p[i]-1)+1)/3 = 1/3 mod p[i]-1 */
        decr(p[i],1,kd);
        premult(kd,2,kd);
        incr(kd,1,kd);
        subdiv(kd,3,kp[i]);
    }
    crt_init(&ch,NP,p);
    nroot(ke,3,mn);
    multiply(mn,mn,m);
    multiply(mn,m,mx);
    subtract(mx,m,mx);
    do
    { /* get input file */
        printf("file to be decoded = ");
        gets(ifname);
    } while (strlen(ifname)==0);
    strip(ifname);
    strcat(ifname,".rsa");
    printf("output filename = ");
    gets(ofname);
    flo=FALSE;
    if (strlen(ofname)>0) 
    { /* set up output file */
        flo=TRUE;
        ofile=fopen(ofname,"w");
    }
    printf("decoding message\n");
    if ((ifile=fopen(ifname,"r"))==NULL)
    {
        printf("Unable to open file %s\n",ifname);
        return 0;
    }
    forever
    { /* decode line by line */
        mip->IOBASE=60;
        cinnum(m,ifile);
        if (size(m)==0) break;
        for (i=0;i<NP;i++)
            powmod(m,kp[i],p[i],ep[i]);
        crt(&ch,ep,e);    /* Chinese remainder thereom */
        if (compare(e,mx)>=0) divide(e,mn,mn);
        mip->IOBASE=128;
        if (flo) cotnum(e,ofile);
        cotnum(e,stdout);
    }
    crt_end(&ch);
    fclose(ifile);
    if (flo) fclose(ofile);
    printf("message ends\n");
    return 0;
}
Beispiel #24
0
 void update(int l,int r,int k) {
     push();
     for(int i=l; i<=r; i++)
         a[i%cs]=k;
     crt();
 }