Exemple #1
0
int gcd(int a, int b) {
    if (b) return gcd(b, a%b);
    return a;
}
Exemple #2
0
int main(){
  scanf("%lld %d", &n, &q);
  for (int i = 0; i < q; i++)
    scanf("%d %lld", &seq[i].second, &seq[i].first);
  qsort(seq, q, sizeof(pair), cmpP);
  int fir = 0;
  while (seq[fir].second == 0)
    fir++;
  int lst = q - 1;
  while (seq[lst].second == 0)
    lst--;
  ll cur = 0;
  ll obt = -1;
  for (int i = 0; i < q; i++){
    if(seq[i].second == 0)
      mem[i] = obt == -1? cur: gcd(cur, seq[i].first - obt);
    else{
      if (obt != -1)
        cur = gcd(cur, seq[i].first - obt);
      obt = seq[i].first;
    }
  }
  for(ll i = 1; i * i <= cur; i++){
    if (cur % i == 0){
      dvs.ptr = pushback(dvs.ptr, &dvs.sz, i);
      if(i*i < cur)
        dvs.ptr = pushback(dvs.ptr, &dvs.sz, cur/i);
    }
  }
  qsort(dvs.ptr, dvs.sz, sizeof(ll), cmpLL);
  for(int i = 0; i < dvs.sz; i++){
    mn[i] = 1;
    mx[i] = n;
  }
  cur = 0;
  obt = -1;
  for(int i = q - 1; i >= 0; i--){
    if(seq[i].second == 0){
      ll newmem = obt == -1? cur: gcd(cur, obt - seq[i].first);
      ll nd = gcd(mem[i], newmem);
      int ind = lower_bound(dvs.ptr, dvs.sz, nd);
      if (ind < dvs.sz && dvs.ptr[ind] == nd){
        if (i < fir)
          mn[ind] = max(mn[ind], seq[i].first + 1);
        else if (i < lst) { 
          mn[ind] = n + 1, 
          mx[ind] = 0;
        }
        else 
          mx[ind] = min(mx[ind], seq[i].first - 1);
      }
    }
    else {
      if (obt != -1)
        cur = gcd(cur, obt - seq[i].first);
      obt = seq[i].first;
    }
  }
  for (int i = dvs.sz - 1; i >= 0; i--){
    for (int j = i + 1; j < dvs.sz; j++){
      if(dvs.ptr[j] % dvs.ptr[i] == 0){
        mn[i] = max(mn[i], mn[j]);
        mx[i] = min(mx[i], mx[j]);
      }
    }
    ll a = mn[i] <= seq[fir].first? 1 + (seq[fir].first - mn[i]) / dvs.ptr[i]: 0;
    ll b = seq[lst].first <= mx[i]? 1 + (mx[i] - seq[lst].first) / dvs.ptr[i]: 0;
    a %= mod;
    b %= mod;
    res = (res + a * b) % mod;
  }
  printf("%d\n", res);
  return 0;
}
Exemple #3
0
/* Break a mask into boxes.
 */
static Boxes *
boxes_new( IMAGE *in, IMAGE *out, DOUBLEMASK *mask, int n_layers, int cluster )
{
	const int size = mask->xsize * mask->ysize;

	Boxes *boxes;
	double sum;
	int x, y, z;

	/* Check parameters.
	 */
	if( im_piocheck( in, out ) ||
		im_check_uncoded( "im_aconv", in ) ||
		vips_check_dmask( "im_aconv", mask ) ) 
		return( NULL );

	boxes = VIPS_NEW( out, Boxes );
	boxes->in = in;
	boxes->out = out;
	if( !(boxes->mask = (DOUBLEMASK *) im_local( out, 
		(im_construct_fn) im_dup_dmask,
		(im_callback_fn) im_free_dmask, mask, mask->filename, NULL )) )
		return( NULL );
	boxes->n_layers = n_layers;
	boxes->cluster = cluster;

	boxes->n_hline = 0;
	boxes->n_velement = 0;
	boxes->n_vline = 0;

	/* Break into a set of hlines.
	 */
	if( boxes_break( boxes ) )
		return( NULL );

	/* Cluster to find groups of lines.
	 */
	VIPS_DEBUG_MSG( "boxes_new: clustering with thresh %d ...\n", cluster );
	while( boxes_cluster2( boxes, cluster ) )
		;

	/* Renumber to remove holes created by clustering.
	 */
	boxes_renumber( boxes );

	/* Find a set of vlines for the remaining hlines.
	 */
	boxes_vline( boxes );

	/* Find the area of the lines and the length of the longest hline.
	 */
	boxes->area = 0;
	boxes->max_line = 0;
	for( y = 0; y < boxes->n_velement; y++ ) {
		x = boxes->velement[y].band;
		z = boxes->hline[x].end - boxes->hline[x].start;

		boxes->area += boxes->velement[y].factor * z;
		if( z > boxes->max_line )
			boxes->max_line = z;
	}

	/* Strength reduction: if all lines are divisible by n, we can move
	 * that n out into the ->area factor. The aim is to produce as many
	 * factor 1 lines as we can and to reduce the chance of overflow.
	 */
	x = boxes->velement[0].factor;
	for( y = 1; y < boxes->n_velement; y++ ) 
		x = gcd( x, boxes->velement[y].factor );
	for( y = 0; y < boxes->n_velement; y++ ) 
		boxes->velement[y].factor /= x;
	boxes->area *= x;

	/* Find the area of the original mask.
	 */
	sum = 0;
	for( z = 0; z < size; z++ ) 
		sum += mask->coeff[z];

	boxes->area = rint( sum * boxes->area / mask->scale );
	boxes->rounding = (boxes->area + 1) / 2 + mask->offset * boxes->area;

#ifdef DEBUG
	boxes_hprint( boxes );
	boxes_vprint( boxes );
#endif /*DEBUG*/

	/* With 512x512 tiles, each hline requires 3mb of intermediate per
	 * thread ... 300 lines is about a gb per thread, ouch.
	 */
	if( boxes->n_hline > 150 ) {
		im_error( "im_aconv", "%s", _( "mask too complex" ) );
		return( NULL );
	}

	return( boxes );
}
Exemple #4
0
time_hrts lcm(time_hrts m, time_hrts n) {
    return m / gcd(m, n) * n;
}
Exemple #5
0
bool sample_rate_frac_set(uint32_t rate_num, uint32_t rate_denom)
{
	const uint64_t VCO_FREQ = 800 * 1000 * 1000; /* 800 MHz */
	uint32_t MSx_P1,MSx_P2,MSx_P3;
	uint32_t a, b, c;
	uint32_t rem;

	hackrf_ui_setSampleRate(rate_num/2);

	/* Find best config */
	a = (VCO_FREQ * rate_denom) / rate_num;

	rem = (VCO_FREQ * rate_denom) - (a * rate_num);

	if (!rem) {
		/* Integer mode */
		b = 0;
		c = 1;
	} else {
		/* Fractional */
		uint32_t g = gcd(rem, rate_num);
		rem /= g;
		rate_num /= g;

		if (rate_num < (1<<20)) {
			/* Perfect match */
			b = rem;
			c = rate_num;
		} else {
			/* Approximate */
			c = (1<<20) - 1;
			b = ((uint64_t)c * (uint64_t)rem) / rate_num;

			g = gcd(b, c);
			b /= g;
			c /= g;
		}
	}

	/* Can we enable integer mode ? */
	if (a & 0x1 || b)
		si5351c_set_int_mode(&clock_gen, 0, 0);
	else
		si5351c_set_int_mode(&clock_gen, 0, 1);

	/* Final MS values */
	MSx_P1 = 128*a + (128 * b/c) - 512;
	MSx_P2 = (128*b) % c;
	MSx_P3 = c;

	/* MS0/CLK0 is the source for the MAX5864/CPLD (CODEC_CLK). */
	si5351c_configure_multisynth(&clock_gen, 0, MSx_P1, MSx_P2, MSx_P3, 1);

	/* MS0/CLK1 is the source for the CPLD (CODEC_X2_CLK). */
	si5351c_configure_multisynth(&clock_gen, 1, 0, 0, 0, 0);//p1 doesn't matter

	/* MS0/CLK2 is the source for SGPIO (CODEC_X2_CLK) */
	si5351c_configure_multisynth(&clock_gen, 2, 0, 0, 0, 0);//p1 doesn't matter

	return true;
}
Exemple #6
0
//add the two numbers
char* add_nums(const char* num1,const char* base1,const char* num2,const char* base2)
{
	const char* base_str[2];
	const char* num_str[2];
	char *p,*q;
	int base_gcd;
	int i,test_res;
	int base[2];
	ln numerator[3],denominator[3];
	vector digits;

	//test bases
	base_str[0]=base1;
	base_str[1]=base2;
	for(i=0;i<2;i++)
	{
		base[i]=test_base(base_str[i]);
		if(base[i]==-1)
		{
			printf("Error: invalid base [%s]!\n",base_str[i]);
			return NULL;
		}
		else if(base[i]==-2)
		{
			printf("Error: base [%s] is out of range "MACRO2STR(MIN_BASE)"-"MACRO2STR(MAX_BASE)"!\n",base_str[i]);
			return NULL;
		}
	}

	//test numbers 
	num_str[0]=num1;
	num_str[1]=num2;
	for(i=0;i<2;i++)
	{
		test_res=test_num(num_str[i],base[i]);
		if(test_res==0)
		{
			printf("Error: invalid number [%s],the number should match the regular expression [0-9]+(.[0-9]+)? !\n",num_str[i]);
			return NULL;
		}
		else if(test_res==2)
		{
			printf("Error: invalid number [%s] in base %d !\n",num_str[i],base[i]);
			return NULL;
		}
	}

	//convert the two numbers into fraction form
	for(i=0;i<2;i++)
	{
		denominator[i]=get_denominator(num_str[i],base[i]);
		numerator[i]=get_numerator(num_str[i],base[i]);
	}

	for(i=0;i<2;i++)
	{
		p=ln2str(numerator[i]);
		q=ln2str(denominator[i]);
		printf("operand in fraction:%s/%s\n",p,q);
		fflush(stdout);
		free(p);
		free(q);
	}
	//compute the fraction
	denominator[2]=ln_multiply(denominator[0],denominator[1],newln);
	numerator[0]=ln_multiply(numerator[0],denominator[1],firstln);
	numerator[1]=ln_multiply(numerator[1],denominator[0],firstln);
	numerator[2]=ln_add(numerator[0],numerator[1],newln);
	//free unused numbers
	for(i=0;i<2;i++)
	{
		ln_free(&(numerator[i]));
		ln_free(&(denominator[i]));
	}


	p=ln2str(numerator[2]);
	q=ln2str(denominator[2]);
	printf("result in fraction:%s/%s\n",p,q);


	//simplifying the result fraction
	base_gcd=gcd(base[0],base[1]);
	if(base_gcd !=1)
	{
		while(ln_divideable_num(numerator[2],base_gcd)==1 && ln_divideable_num(denominator[2],base_gcd)==1)
		{

			ln_divide_int(numerator[2],base_gcd,0,trunc_res,firstln);
			ln_divide_int(denominator[2],base_gcd,0,trunc_res,firstln);
		}
	}

	p=ln2str(numerator[2]);
	q=ln2str(denominator[2]);
	printf("result in fraction:%s/%s\n",p,q);
	fflush(stdout);
	if(strcmp(q,"1")==0)
	{
		free(q);
		q=(char*)malloc(strlen(p)+4);
		if(!q)
		{
			ln_free(&(numerator[2]));
			ln_free(&(denominator[2]));
			printf("Error: coverting fraction to decimal number failed at line %d",__LINE__);
			return NULL;
		}
		sprintf(q,"%s 10",p);
		free(p);
		return q;
	}




	free(p);
	free(q);
	digits=get_decimal_digit(numerator[2],denominator[2]);
	if(!digits)
	{
		ln_free(&(numerator[2]));
		ln_free(&(denominator[2]));
		printf("Error: coverting fraction to decimal number failed at line %d",__LINE__);
		return NULL;
	}

	p=get_decimalstr(digits,denominator[2]);
	if(!p)
	{
		ln_free(&(numerator[2]));
		ln_free(&(denominator[2]));
		free_digit(digits);
		printf("Error: coverting fraction to decimal number failed at line %d",__LINE__);
		return NULL;
	}
	return p;
}
bool UniversalInstantiator::process_ilp_leaf_in_index_guard(ILPLeaf* ilp,
		set<int> &qvars, QuantifiedLeaf* ql)
{
	int qvar_id = -1;
	int qvar_coef = 1;
	bool seen_non_zero_coef = false;
	bool seen_two_uvars = false;
	long int running_gcd = 0;
	map<Term*, long int> new_elems;

	//ArithmeticTerm* se = new ArithmeticTerm();
	map<Term*, long int >::const_iterator it = ilp->get_elems().begin();
	for(; it!=ilp->get_elems().end(); it++)
	{
		Term* t= it->first;
		int coef = it->second;

		if(t->get_term_type() == FUNCTION_TERM) return false;
		if(t->get_term_type() == CONSTANT_TERM) continue;
		VariableTerm* vt = (VariableTerm*) t;
		int var_id = vt->get_var_id();

		// Universally quantified variable
		if(qvars.count(var_id) > 0){
			if(qvar_id!=-1){
				if(coef == 0) continue;
				// not legal
				if(ilp->get_constant() != 0 ){
					return false;
				}
			}
			else {
				qvar_id = var_id;
				qvar_coef = coef;
				continue;
			}
		}

		// Non-univerally quantified variable
		if(coef != 0) seen_non_zero_coef = true;
		new_elems[vt] = -coef;
		running_gcd = gcd(running_gcd, coef);

	}

	if(seen_two_uvars && seen_non_zero_coef){
		return false;
	}
	if(qvar_id == -1){
		return true;
	}
	if(running_gcd % qvar_coef != 0){
		return false;
	}

	Term* se = NULL;
	if(qvar_coef != 1){
		map<Term*, long int>  new_set;
		map<Term*, long int>::iterator it2 = new_elems.begin();
		for(; it2!=new_elems.end(); it2++){
			new_set[it2->first] = it2->second/qvar_coef;
		}
		se = ArithmeticTerm::make(new_set, ilp->get_constant()/qvar_coef);
	}
	else {
		se = ArithmeticTerm::make(new_elems, ilp->get_constant());
	}
	qvar qv;
	//qv.orig_id = ql->get_orig_id();
	qv.id = (long int) ql;
	qv.var_id = qvar_id;

	add_to_index_set(qv, se);
	return true;
}
Exemple #8
0
int gcd(int o,int p)
{
    if (p==0) {return o;} else {return gcd(p,o%p);}
}
Exemple #9
0
int lcm(int m, int n)
{
    return m * n / gcd(m, n);
}
Exemple #10
0
int gcd(int a, int b)
{
	return (b==0)	?  a   :   gcd(b,a%b);
}
LL gcd(LL a, LL b)
{
	if (b == 0) return a;
	return gcd(b, a%b);
}
intx gcd(intx a, intx b) {
  return eq(b, intx(0)) ? a : gcd(b, a % b);
}
Exemple #13
0
ll gcd (ll a, ll b) {
	return b == 0 ? a : gcd(b, a%b);
}
Exemple #14
0
static int karlinpp(void *space, int low, int high, double *pr, 
                     double *lambda, double *K)
{
  int i, j, range, lo, hi, first, last;
  double upval, Sumval, av, sum, *p, *P, *ptrP, *ptr1, *ptr2, *ptr1e, newval,
         Ktmp;

  /* Check that scores and their associated probabilities are valid     */

  if (low >= 0)
  {
    NFO("Lowest score %ld must be negative", low);
    return  -1;
  }
  for (i = range = high - low; i > -low && !pr[i]; --i)
    /* Nothing */ ;
  if (i <= -low)
  {
    MSG("A positive score must be possible");
    return  -2;
  }
  for (sum = 0.0, i = 0; i <= range; sum += pr[i++])
  {
    if (pr[i] < 0.0)
    {
      DBG("Negative probability %.2f not allowed",pr[i]);
      return  -3;
    }
  }
  if (sum < 0.99995 || sum > 1.00005)
  {
    DBGL(3,"Probabilities sum to %.4f. Normalizing.\n", sum);
  }
  
  p = ALLOCMEMORY(space, NULL, double, (Uint)(range+100));
  if(p == NULL)
  {
    return  -4;
  }
  for (Sumval = (double) low, i = 0; i <= range; ++i)
  {
    Sumval += i * (p[i] = pr[i] / sum);
  }
  if(Sumval >= 0.0)
  {
    NFO("Invalid (non-negative) expected score:  %.3f", Sumval);
    return  -5;
  }

  /* Calculate the parameter lambda */

  upval = 0.5;
  do
  {
    upval *= 2;
    ptr1 = p;
    for (sum = 0.0, i = low; i <= high; ++i)
    {
      sum += *ptr1++ * exp (upval * i);
    }
  } while (sum < 1.0);
  for (*lambda = 0.0, j = 0; j <  40; ++j)
  {
    newval = (*lambda + upval) / 2.0;
    ptr1 = p;
    for (sum = 0.0, i = low; i <= high; ++i)
    {
      sum += *ptr1++ * exp (newval * i);
    }
    if (sum > 1.0)
    {
      upval = newval;
    } else
    {
      *lambda = newval;
    }
  }

  /* Calculate the pamameter K */

  ptr1 = p;
  for (av = 0.0, i = low; i <= high; ++i)
  {
    av += *ptr1++ * i * exp (*lambda * i);
  }
  if (low ==  -1 || high ==  1)
  {
    *K = (high ==  1) ? av : Sumval * Sumval / av;
    *K *= 1.0 - exp (-*lambda);
    free (p);
    return 0;  /* Parameters calculated successfully */
  }
  Sumval = 0.0;
  lo = 0;
  hi = 0;
  P = ALLOCMEMORY(space, NULL,double,(Uint) (MAXIT * range + 100));
  if(P == NULL)
  {
    return  -6;
  }
  for (*P = 1.0, sum = 1.0, j =  1; 
       j <=  MAXIT && sum > 0.00001; Sumval += sum /= j++)
  {
    first = last = range;
    for (ptrP = P + (hi += high) - (lo += low); ptrP >= P; *ptrP-- = sum)
    {
      ptr1 = ptrP - first;
      ptr1e = ptrP - last;
      ptr2 = p + first;
      for (sum = 0.0; ptr1 >= ptr1e;)
      {
        sum += *ptr1-- * *ptr2++;
      }
      if (first)
      {
        --first;
      }
      if (( (ptrP - P)) <= range)
      {
        --last;
      }
    }
    for (sum = 0.0, i = lo; i; ++i)
    {
      sum += *++ptrP * exp (*lambda * i);
    }
    for (; i <= hi; ++i)
    {
      sum += *++ptrP;
    }
  }
  if (j >  MAXIT)
  {
    MSG("Value for K may be too large due to insufficient iterations");
    return  -7;
  }
  for (i = low; !p[i - low]; ++i)
    /* Nothing */ ;
  for (j = -i; i < high && j >  1;)
  {
    if (p[++i - low] != 0.0)
    {
      j = gcd (j, i);
    }
  }
  Ktmp = (double) (j * exp (-2 * Sumval));
  *K = Ktmp / (av * (1.0 - exp (-*lambda * j)));

  FREEMEMORY(space, P);
  FREEMEMORY(space, p);
  return 0;  /* Parameters calculated successfully */
}
Exemple #15
0
int relPrime( unsigned a, unsigned b ){
    if (gcd(a, b) == 1) return 1; //If the greatest common denominator of two numbers is equal to 1, the two numbers must necessarily be relatively prime.
    return 0;
}
Exemple #16
0
int get_divider(struct fb_info *fb)
{
	struct s3cfb_window *win = fb->par;
	struct s3cfb_global *fbdev = get_fimd_global(win->id);
	struct lcdfreq_info *lcdfreq = fbdev->data;
	struct clksrc_clk *sclk;
	struct clk *clk;
	u32 rate, reg, i;
	u8 fimd_div;

	sclk = container_of(fbdev->clock, struct clksrc_clk, clk);
	clk = clk_get_parent(clk_get_parent(fbdev->clock));
	rate = clk_get_rate(clk);

	lcdfreq->table[LEVEL_NORMAL].cmu_clkdiv =
		DIV_ROUND_CLOSEST(rate, lcdfreq->table[LEVEL_NORMAL].vclk);

	lcdfreq->table[LEVEL_LIMIT].cmu_clkdiv =
		DIV_ROUND_CLOSEST(rate, lcdfreq->table[LEVEL_LIMIT].vclk);

	fimd_div = gcd(lcdfreq->table[LEVEL_NORMAL].cmu_clkdiv, lcdfreq->table[LEVEL_LIMIT].cmu_clkdiv);

	if ((!fimd_div) || (fimd_div > 16)) {
		dev_info(fb->dev, "%s skip, %d\n", __func__, __LINE__);
		goto err;
	}

	lcdfreq->table[LEVEL_NORMAL].cmu_clkdiv /= fimd_div;
	lcdfreq->table[LEVEL_LIMIT].cmu_clkdiv /= fimd_div;

	dev_info(fb->dev, "%s rate is %d, fimd divider=%d\n", clk->name, rate, fimd_div);

	fimd_div--;
	for (i = 0; i < LCDFREQ_LEVEL_END; i++) {
		if (lcdfreq->table[i].cmu_clkdiv > 16) {
			dev_info(fb->dev, "%s skip, %d\n", __func__, __LINE__);
			goto err;
		}
		dev_info(fb->dev, "%dhz div is %d\n",
		lcdfreq->table[i].hz, lcdfreq->table[i].cmu_clkdiv);
		lcdfreq->table[i].cmu_clkdiv--;
	}

	reg = (readl(fbdev->regs + S3C_VIDCON0) & (S3C_VIDCON0_CLKVAL_F(0xff))) >> 6;
	if (fimd_div != reg) {
		dev_info(fb->dev, "%s skip, %d\n", __func__, __LINE__);
		goto err;
	}

	reg = (readl(sclk->reg_div.reg)) >> sclk->reg_div.shift;
	reg &= 0xf;
	if (lcdfreq->table[LEVEL_NORMAL].cmu_clkdiv != reg) {
		dev_info(fb->dev, "%s skip, %d\n", __func__, __LINE__);
		goto err;
	}

	return 0;

err:
	return -EINVAL;
}
Exemple #17
0
int lcm(int a, int b) {
	int temp = gcd(a, b);
	return temp ? (a / temp * b) : 0;
}
Exemple #18
0
int gcd(int a, int b)
{
    return b==0?a:gcd(b, a%b);
}
Exemple #19
0
int gcd(int a,int b)
{
	if(b == 0)
		return a;
	return gcd(b,a%b);
}
Exemple #20
0
/***************************************************************************//**
 * @brief Sets the ADF4351 frequency on the specified channel.
 *
 * @param st - The selected structure.
 * @param freq - The desired frequency value.
 * @param channel - 0 = RX channel, 1 = TX channel 
 *
 * @return calculatedFrequency - The actual frequency value that was set.
*******************************************************************************/
int64_t adf4351_set_freq(struct adf4351_state *st, uint64_t freq,
							char channel)
{
	struct adf4351_platform_data *pdata = st->pdata;
	uint64_t tmp;
	uint32_t div_gcd, prescaler, chspc;
	uint16_t mdiv, r_cnt = 0;
	uint8_t band_sel_div;
	int32_t ret;

	if ((freq > ADF4351_MAX_OUT_FREQ) || (freq < ADF4351_MIN_OUT_FREQ))
		return -1;

	if (freq > ADF4351_MAX_FREQ_45_PRESC) {
		prescaler = ADF4351_REG1_PRESCALER;
		mdiv = 75;
	} else {
		prescaler = 0;
		mdiv = 23;
	}

	st->r4_rf_div_sel = 0;

	while (freq < ADF4351_MIN_VCO_FREQ) {
		freq <<= 1;
		st->r4_rf_div_sel++;
	}

	/*
	 * Allow a predefined reference division factor
	 * if not set, compute our own
	 */
	if (pdata->ref_div_factor)
		r_cnt = pdata->ref_div_factor - 1;

	chspc = st->chspc;

	do  {
		do {
	do  {
		r_cnt = adf4351_tune_r_cnt(st, r_cnt);
				st->r1_mod = st->fpfd / chspc;
				if (r_cnt > ADF4351_MAX_R_CNT) {
					/* try higher spacing values */
					chspc++;
					r_cnt = 0;
		}
			} while ((st->r1_mod > ADF4351_MAX_MODULUS) && r_cnt);
		} while (r_cnt == 0);


		tmp = freq * (uint64_t)st->r1_mod + (st->fpfd > 1);
		
		tmp = (tmp / st->fpfd);	/* Div round closest (n + d/2)/d */
		
		st->r0_fract = tmp % st->r1_mod;
		tmp = tmp / st->r1_mod;
		
		st->r0_int = (uint32_t)tmp;
	} while (mdiv > st->r0_int);

	band_sel_div = st->fpfd % ADF4351_MAX_BANDSEL_CLK > ADF4351_MAX_BANDSEL_CLK / 2 ?
					st->fpfd / ADF4351_MAX_BANDSEL_CLK + 1 :
					st->fpfd / ADF4351_MAX_BANDSEL_CLK;

	if (st->r0_fract && st->r1_mod) {
		div_gcd = gcd(st->r1_mod, st->r0_fract);
		st->r1_mod /= div_gcd;
		st->r0_fract /= div_gcd;
	} else {
		st->r0_fract = 0;
		st->r1_mod = 1;
	}

	st->regs[ADF4351_REG0] = ADF4351_REG0_INT(st->r0_int) |
				 ADF4351_REG0_FRACT(st->r0_fract);

	st->regs[ADF4351_REG1] = ADF4351_REG1_PHASE(1) |
				 ADF4351_REG1_MOD(st->r1_mod) |
				 prescaler;

	st->regs[ADF4351_REG2] =
		ADF4351_REG2_10BIT_R_CNT(r_cnt) |
		ADF4351_REG2_DOUBLE_BUFF_EN |
		(pdata->ref_doubler_en ? ADF4351_REG2_RMULT2_EN : 0) |
		(pdata->ref_div2_en ? ADF4351_REG2_RDIV2_EN : 0) |
		(pdata->r2_user_settings & (ADF4351_REG2_PD_POLARITY_POS |
		ADF4351_REG2_LDP_6ns | ADF4351_REG2_LDF_INT_N |
		ADF4351_REG2_CHARGE_PUMP_CURR_uA(5000) |
		ADF4351_REG2_MUXOUT(0x7) | ADF4351_REG2_NOISE_MODE(0x3)));

	st->regs[ADF4351_REG3] = pdata->r3_user_settings &
				 (ADF4351_REG3_12BIT_CLKDIV(0xFFF) |
				 ADF4351_REG3_12BIT_CLKDIV_MODE(0x3) |
				 ADF4351_REG3_12BIT_CSR_EN |
				 ADF4351_REG3_CHARGE_CANCELLATION_EN |
				 ADF4351_REG3_ANTI_BACKLASH_3ns_EN |
				 ADF4351_REG3_BAND_SEL_CLOCK_MODE_HIGH);

	st->regs[ADF4351_REG4] =
		ADF4351_REG4_FEEDBACK_FUND |
		ADF4351_REG4_RF_DIV_SEL(st->r4_rf_div_sel) |
		ADF4351_REG4_8BIT_BAND_SEL_CLKDIV(band_sel_div) |
		ADF4351_REG4_RF_OUT_EN |
		(pdata->r4_user_settings &
		(ADF4351_REG4_OUTPUT_PWR(0x3) |
		ADF4351_REG4_AUX_OUTPUT_PWR(0x3) |
		ADF4351_REG4_AUX_OUTPUT_EN |
		ADF4351_REG4_AUX_OUTPUT_FUND |
		ADF4351_REG4_MUTE_TILL_LOCK_EN));

	st->regs[ADF4351_REG5] = ADF4351_REG5_LD_PIN_MODE_DIGITAL;

	ret = adf4351_sync_config(st, channel);
	if(ret < 0)
		return ret;

    tmp = (uint64_t)((st->r0_int * st->r1_mod) + st->r0_fract) * (uint64_t)st->fpfd;
    tmp = tmp / ((uint64_t)st->r1_mod * ((uint64_t)1 << st->r4_rf_div_sel));

	return tmp;
}
Exemple #21
0
/////////////////////////////////////////////////////////////////////////////
// Implementation when type  is arithmetic_
/////////////////////////////////////////////////////////////////////////////
NT2_REGISTER_DISPATCH(tag::lcm_, tag::cpu_,
                      (A0)(X),
                      ((simd_<arithmetic_<A0>,X>))
                      ((simd_<arithmetic_<A0>,X>))
                     );

namespace nt2 { namespace ext
{
  template<class X, class Dummy>
  struct call<tag::lcm_(tag::simd_<tag::arithmetic_, X> ,
                        tag::simd_<tag::arithmetic_, X> ),
              tag::cpu_, Dummy> : callable
  {
    template<class Sig> struct result;
    template<class This,class A0>
    struct result<This(A0,A0)>
      : meta::strip<A0>{};//

    NT2_FUNCTOR_CALL(2)
    {
      return nt2::abs(round2even(a0)*rdivide(round2even(a1), gcd(a0,a1)));
    }

  };
} }

#endif
// modified by jt the 05/01/2011
// computes lcm(a,b)
int lcm(int a, int b) {
  return a/gcd(a,b)*b;
}
Exemple #23
0
unsigned long lcm(unsigned long a, unsigned long b)
{
  unsigned long long p = (unsigned long long)a * b;
  return p/gcd(a, b);
}
int main(void){
	printf("GCD Test (45, 30) expected 15, actual: %d", gcd(45, 30));
	printf("\nGCD Test (100, 5) expected 5, actual: %d", gcd(100, 5));
	printf("\nGCD Test (44, 144) expected 4, actual: %d\n", gcd(44, 144));
	return 0;
}
Exemple #25
0
int gcd(int x,int y) {
    return y==0?x:gcd(y,x%y);
}
Exemple #26
0
ll gcd(ll x, ll y){
  return x? gcd(y % x, x): y;
}