Ejemplo n.º 1
0
INT X(choose_radix)(INT r, INT n)
{
     if (r > 0) {
	  if (divides(r, n)) return r;
	  return 0;
     } else if (r == 0) {
	  return X(first_divisor)(n);
     } else {
	  /* r is negative.  If n = (-r) * q^2, take q as the radix */
	  r = 0 - r;
	  return (n > r && divides(r, n)) ? isqrt_maybe(n / r) : 0;
     }
}
Ejemplo n.º 2
0
// does n divide m?
int divides(int n, int m) {
    if (m == 0) {
        return 1; // true
    }
    if (n > m) {
        return 0; // false
    }
    return divides(n, m - n);
}
Ejemplo n.º 3
0
bool prime (uint n) {
  uint i;
  if (even (n))
      return (n == 2);
  for (i = 3; i * i <= n; i += 2) {
      if (divides (i, n)) /* ai: loop here min 0 max 357 end; */
          return 0;
  }
  return (n > 1);
}
Ejemplo n.º 4
0
TEST(factors, divides_zero) {
    EXPECT_TRUE(divides(1, 0));
    EXPECT_TRUE(divides(2, 0));
    EXPECT_TRUE(divides(3, 0));
    EXPECT_FALSE(divides(0, 0));
    EXPECT_FALSE(divides(0, 1));
    EXPECT_FALSE(divides(0, 2));
    EXPECT_FALSE(divides(0, 3));
}
Ejemplo n.º 5
0
unsigned long smallest_divisor(int n) {
  int divisor = 2;

  for (;;) {
    if (square(divisor) > n)
      return n;
    else if (divides(divisor, n))
      return divisor;
    else
      divisor++;
  }
}
Ejemplo n.º 6
0
int
common(unsigned long b, unsigned long a){

  unsigned long i;

  for (i=2; i<min(a,b); i++)
     if(is_prime(i)){
     int ax, bx;
     ax = divides(i,a); 
     bx = divides(i,b);

     //printf (" %lu %lu  %d   %lu  %lu %d  ", a, i, ax, b, i, bx);
     if ( ax & bx) {
        //printf(" true, common \n");
        return 1;
     }
    //printf("\n");
  }
  //printf(" false, no common \n");
  return 0;
}
Ejemplo n.º 7
0
int X(dft_ct_applicable)(const solver_ct *ego, const problem *p_)
{
     if (DFTP(p_)) {
          const problem_dft *p = (const problem_dft *) p_;
          const ct_desc *d = ego->desc;
          return (   p->sz->rnk == 1
                  && p->vecsz->rnk <= 1
                  && divides(d->radix, p->sz->dims[0].n)
	       );
     }
     return 0;
}
Ejemplo n.º 8
0
int main() {
    /*
    std::vector<long> primes;

    primes.push_back(2);
    primes.push_back(3);
    primes.push_back(5);


    Range r(2, 100);
    for (RangeIterator ri = r.begin(); ri != r.end(); ri++) {
        //std::cout << *ri << std::endl;
        bool prime = true;
        double end = sqrt(*ri);
        for (std::vector<long>::const_iterator pi = primes.begin(); pi != primes.end(); pi++) {
            if (divides(*pi, *ri))  {
                prime = false;
                break;
            } else if (*pi > end) {
                break;
            }
        }
        if (prime) {
            primes.push_back(*ri);
        }
    }
    print_vector(&primes);*/

    //int n = 13195;
    long n = 600851475143;
    Range r2(2, sqrt(n)+1);
    long largest = 1;
    while (true) {
        bool divided = false;
        for (RangeIterator ri = r2.begin(); ri != r2.end(); ri++) {
            if (divides(*ri, n)) {
                n /= *ri;
                if (*ri > largest) {
                    largest = *ri;
                }
                divided = true;
                break;
            }
        }
        if (!divided) {
            break;
        }
    }
    std::cout << largest << std::endl;

    return 0;
}
Ejemplo n.º 9
0
bool prime (uint n) {
  uint i;
  if (even (n))
      return (n == 2);
  _Pragma("loopbound min 73 max 357")
  __llvm_pcmarker(0);
  for (i = 3; i * i <= n; i += 2) { 
      __llvm_pcmarker(1);
      if (divides (i, n)) /* ai: loop here min 0 max 357 end; */
          return 0; 
  }
  return (n > 1);
}
Ejemplo n.º 10
0
int
findfactors (long double find){

  long double i;
  int factors = 0;
  long double max = sqrtl(find) + 1 ;
  for ( i = 1 ; i <= max;  i++){
    if (divides(i, find)) {
//        printf("%0.0Lf ", i);
        factors++;
    } 
  }

  return factors*2;
}
Ejemplo n.º 11
0
/*
 * Perform simple optimization:
 * if h = k*g for some generators g!=h and natural number k, then remove h from generators
 */
void clean_generators_simple(LinSet &ls) {
  // check for all pairs of generators (g,h) if divides(h,g)
  for(auto g = ls.second.begin(); g!=ls.second.end(); ++g) {
    for(auto h = ls.second.begin(); h!=ls.second.end();) {
      if(g==h){
        ++h;
        continue;
      }
      if(divides(*g,*h)) {
        h = ls.second.erase(h);
      }
      else
        ++h;
    }
  }
}
int main() {
    int m = __VERIFIER_nondet_int();
    if (m <= 0 || m > 2147483647) {
        return 0;
    }
    int n = __VERIFIER_nondet_int();
    if (n <= 0 || n > 2147483647) {
        return 0;
    }
    if (m > 0 && n > 0) {
        int z = gcd(m, n);
        if (divides(z, m) == 0) {
            ERROR: __VERIFIER_error();
        } else {
            return 0;
        }
    }
}
Ejemplo n.º 13
0
TEST(factors, divides_simple) {
    EXPECT_TRUE(divides(1, 1));
    EXPECT_TRUE(divides(1, 2));
    EXPECT_TRUE(divides(1, 3));
    EXPECT_TRUE(divides(2, 2));
    EXPECT_TRUE(divides(2, 4));
    EXPECT_TRUE(divides(3, 3));
    EXPECT_TRUE(divides(3, 6));
    EXPECT_FALSE(divides(2, 1));
    EXPECT_FALSE(divides(3, 1));
    EXPECT_FALSE(divides(2, 3));
    EXPECT_FALSE(divides(4, 6));
    EXPECT_FALSE(divides(5, 6));
    EXPECT_FALSE(divides(7, 6));
}
Ejemplo n.º 14
0
static vl::Error
forward_backward
(vl::Context& context,
 type* output,
 type* derData,
 type* derGrid,
 type const* data,
 type const* grid,
 type const* derOutput,
 size_t outHeight, size_t outWidth, size_t outDepth, size_t outCardinality,
 size_t inHeight, size_t inWidth, size_t inCardinality)
{
  vl::Error error = vl::vlSuccess ;

  bool backward = backwardData | backwardGrid ;

  // common conditions
  assert(grid) ;
  assert(divides(inCardinality, outCardinality)) ;

  // forward conditions
  assert(backward || data) ;
  assert(backward || output) ;

  // backward conditions
  assert(!backward || derOutput) ;
  assert(!backwardData || derData) ;
  assert(!backwardGrid || derGrid) ;
  assert(!backwardGrid || data) ;

  int groupSize = outCardinality / inCardinality ;

  // don't need these -- as already being initialized with zeros in the mex file:
  // if (backwardData) {
  //   memset(derData, 0, inHeight * inWidth * outDepth * inCardinality * sizeof(type)) ;
  // }
  // if (backwardGrid) {
  //   memset(derGrid, 0, 2 * outHeight * outWidth * outCardinality * sizeof(type)) ;
  // }
  for (int n = 0 ; n < outCardinality ; ++n) {
    for (int c = 0 ; c < outDepth ; ++c) {
      type const * end = grid + 2 * outWidth * outHeight ;
      while (grid < end) {
        type py = *grid++ ;
        type px = *grid++ ;

        py = type(0.5)*(py + type(1.0)) * (inHeight - 1) ;
        px = type(0.5)*(px + type(1.0)) * (inWidth - 1) ;
        const int sx = floor(px); // todo: check floor vs floorf
        const int sy = floor(py);

        type acc = 0 ;
        type dgridx = 0 ;
        type dgridy = 0 ;
        type dy ;
        if (backward) {
          dy = *derOutput++ ;
        }

        // todo: check boundary conditions in other frameworks and make
        // them the same
        if (-1 <= sy && sy < inHeight && -1 <= sx && sx < inWidth) {
          // get the interpolation weights
          const type wx = px - sx ;
          const type wy = py - sy ;

          #pragma unroll
          for (int j=0; j < 2; j++) {
            #pragma unroll
            for (int i=0; i < 2; i++) {
              int ssy = sy + i ;
              int ssx = sx + j ;
              if (ssy < 0 || ssy >= inHeight || ssx < 0 || ssx >= inWidth) {
                continue ;
              }
              type wwx = (1-j)*(1-wx) + j*wx ;
              type wwy = (1-i)*(1-wy) + i*wy ;
              type ww = wwx * wwy ;
              if (!backward) {
                acc += ww * data[ssy + ssx * inHeight];
              } else {
                if (backwardData) {
                  derData[ssy + ssx * inHeight] += ww * dy ;
                }
                if (backwardGrid) {
                  type x = data[ssy + ssx * inHeight] ;
                  dgridx += (2*j-1) * wwy * dy * x ;
                  dgridy += (2*i-1) * wwx * dy * x ;
                }
              }
            }
          }
        }
        if (!backward) {
          *output++ = acc ;
        }
        if (backwardGrid) {
          *derGrid++ += type(0.5)*(inHeight - 1) * dgridy ;
          *derGrid++ += type(0.5)*(inWidth - 1) * dgridx ;
        }
      }
      // next channel
      data += inHeight * inWidth ;
      derData +=inHeight * inWidth ;
      grid -= 2 * outHeight * outWidth ;
      derGrid -= 2 * outHeight * outWidth ;
    }
    // next image
    if ((n + 1) % groupSize != 0) {
      data -= inHeight * inWidth * outDepth ;
      derData -= inHeight * inWidth * outDepth ;
    }
    grid += 2 * outHeight * outWidth ;
    derGrid += 2 * outHeight * outWidth ;
  }
  return error ;
}
Ejemplo n.º 15
0
inline
bool even(uint n)
{
        return (divides(2, n));
}
Ejemplo n.º 16
0
bool even (ulong n) {
  return (divides (2, n));
}