Example #1
0
int euclide (int a, int b)
{
	if (b == 0) 
		return a;
	else 
		return euclide(b, a % b);
}
Example #2
0
int main (void)
{
	int num1, num2;
	printf("Calcolo del massimo comun divisore fra due numeri interi\n");
	printf("Primo numero: ");
	scanf("%d", &num1);
	printf("Secondo numero: ");
	scanf("%d", &num2);
	printf("Il massimo comun divisore fra %d e %d รจ: %d\n", num1, num2, euclide(num1,num2));
	return 0;
}
Example #3
0
    void slice_layout::which_slice(const infinint & offset,
				   infinint & slice_num,
				   infinint & slice_offset) const
    {

	    // considering particular case of a non-sliced archive

	if(first_size == 0 || other_size == 0)
	{
	    slice_num = 1;
	    if(offset < first_slice_header)
		slice_offset = first_slice_header;
	    else
		slice_offset = offset - first_slice_header;
	    return;
	}

	    // sanity checks

	if(first_size < first_slice_header)
	    throw SRC_BUG;
	if(other_size < other_slice_header)
	    throw SRC_BUG;
	if(first_slice_header == 0)
	    throw SRC_BUG;
	if(other_slice_header == 0)
	    throw SRC_BUG;

	    // end of sanity checks

        infinint byte_in_first_file = first_size - first_slice_header;
        infinint byte_per_file = other_size - other_slice_header;

	if(!older_sar_than_v8)
	{
	    --byte_in_first_file;
	    --byte_per_file;
		// this is due to the trailing flag (one byte length)
	}

        if(offset < byte_in_first_file)
        {
            slice_num = 1;
            slice_offset = offset + first_slice_header;
        }
        else
        {
	    euclide(offset - byte_in_first_file, byte_per_file, slice_num, slice_offset);
            slice_num += 2;
                // "+2" because file number starts to 1 and first file is already counted
            slice_offset += other_slice_header;
        }
    }
Example #4
0
triple euclide(int a, int b) {
  triple res;
  int q = a / b;
  int r = a % b;
  if (r == 0) {
    res.u=0;
    res.v=1;
    res.d=b;
    return res;
  }
  triple tmp = euclide (b, r);
  res.d = tmp.d;
  res.u = tmp.v;
  res.v = tmp.u - q*tmp.v;
  return res;
}
template<class T> inline T euclide(T a,T b,T &x,T &y)//NOTES:euclide(
  {if(a<0){T d=euclide(-a,b,x,y);x=-x;return d;}
   if(b<0){T d=euclide(a,-b,x,y);y=-y;return d;}
   if(b==0){x=1;y=0;return a;}else{T d=euclide(b,a%b,x,y);T t=x;x=y;y=t-(a/b)*y;return d;}}