示例#1
0
 schur_result ( Input& xpr
                , char jobvs/* = 'V'*/
                , char sort /* = 'N'*/
                , char sense/* = 'N'*/)
   : jobvs_(jobvs)
   , sort_(sort)
   , sense_(sense)
   , a_(xpr)
   , aa_(xpr)
   , n_(nt2::height(xpr))
   , lda_(a_.leading_size())
 {
   BOOST_ASSERT_MSG(is_square(aa_), "Error using schur. Matrix must be square."); 
   jobvs_ = (sense_ == 'E' || sense_ == 'B') ? 'V':jobvs_;
   sort_ = (sense_ == 'E') ? 'S' : sort_; 
   ldvs_ = (jobvs_ == 'N') ? n_ : 1;
   w_.resize(nt2::of_size(n_, 1));
   vs_.resize(of_size(ldvs_, ldvs_));
   ldvs_ = vs_.leading_size(); 
   nt2::details::geesx(&jobvs_, &sort_, &nt2::details::selectall , &sense_, &n_, 
                       aa_.raw(), &lda_, &sdim_, w_.raw(),
                       vs_.raw(), &ldvs_,
                       &rconde_, &rcondv_, 
                       &info_, wrk_);
 }
示例#2
0
文件: print.c 项目: jgan42/bsq
void	print_map(char **map, t_sq *sq)
{
	char	full;
	int		i;
	int		j;

	full = map[0][ft_strlen(map[0]) - 1];
	i = 1;
	while (map[i])
	{
		j = 0;
		while (map[i][j])
		{
			if (is_square(sq, i, j))
			{
				ft_putchar(full);
			}
			else
			{
				ft_putchar(map[i][j]);
			}
			j++;
		}
		ft_putchar('\n');
		i++;
	}
}
T shanks_factor(const T n) {
  static_assert(std::is_signed<T>::value, "Must be signed");
  auto find_factor = [n](const T k) -> T {
    const T sqrt_kn = isqrt(k * n);
    T p = sqrt_kn, old_p;
    T q = (k * n - p * p), old_q = 1;
    if (q == 0)
      return k == 1 ? sqrt_kn : 1;
    auto iterate = [&] {
      old_p = p;
      T b = (sqrt_kn + old_p) / q, tmp;
      p = b * q - old_p;
      tmp = q, q = old_q + b * (old_p - p), old_q = tmp;
    };
    for (size_t i = 1; i % 2 || !is_square(q); ++i)
      iterate();
    const T sqrt_q = isqrt(q);
    const T b = (sqrt_kn - p) / sqrt_q;
    p = b * sqrt_q + p;
    old_q = sqrt_q, q = (k * n - p * p) / old_q;
    do
      iterate();
    while (p != old_p);
    return gcd(n, p);
  };
  const T max_k = std::numeric_limits<T>::max() / n;
  for (T k = 1; k <= max_k; ++k) {
    const T f = find_factor(k);
    if (f != 1 && f != n)
      return f;
  }
  throw std::overflow_error("Can't use a larger multiplier.");
}
示例#4
0
int main(int argc, char ** argv)
{
	long long j, n, max, max_j, x;
	
	if(argc < 2)
		printf("Usage: %s n=%Ld\n", argv[0], n = 1000);
	else
		n = atoi(argv[1]);
	
	max = -1;
	max_j = -1;
	for(j = 2; j <= n; j++)
	{
		if(is_square(j))
			continue;
		
		x = min_x_solution(j);
		printf("%Ld: %Ld\n", j, x);
		if(x > max)
		{
			max = x;
			max_j = j;
		}
	}
	
	printf("Largest minimal x solution for D <= %Ld: %Ld at D = %Ld.\n", 
		n, max, max_j);
	
	return 0;
}
示例#5
0
mask_t is_even_tw(const struct tw_extensible_t* a) {
  struct p448_t L0, L1, L2;
  p448_sqr(&L2, &a->z);
  p448_sqr(&L1, &a->x);
  p448_add(&L0, &L1, &L2);
  p448_weak_reduce(&L0);
  return is_square(&L0);
}
示例#6
0
mask_t is_even_pt(const struct extensible_t* a) {
  struct p448_t L0, L1, L2;
  p448_sqr(&L2, &a->z);
  p448_sqr(&L1, &a->x);
  p448_sub(&L0, &L2, &L1);
  p448_bias(&L0, 2);
  p448_weak_reduce(&L0);
  return is_square(&L0);
}
示例#7
0
void Matrix::eig_sym(Matrix* U, Matrix* L, uint nb_eigenvectors) {
	if(!is_square()) throw std::runtime_error("Matrix must be square");
	Matrix _U,_L;
	_U.init(height, width);
	_L.init(1,width);
	matrix_eigSym2_float(data, _U.data, _L.data, width);
	matrix_sortEig_float(_U.data, _L.data, width);
	*U = _U.trim_height(nb_eigenvectors);
	*L = _L.trim_width(nb_eigenvectors);
}
示例#8
0
文件: 504.c 项目: H-I-D/ProjectEuler
int main(){
	int m = 100;
	// printf("input m: "); scanf("%d", &m);
	int lp_square = 0; // answer
	for(int a = 1; a <= m; a++){
		for(int b = 1; b <= m; b++){
			for(int c = 1; c <= m; c++){
				for(int d = 1; d <= m; d++){
					if(is_square(a, b, c, d)) lp_square++;
				}
			}
		}
	}
	printf("answer: %d\n", lp_square);
}
int main()
{
    int N=0, k=0;
    if (!input("N", &N)) printf("INPUT ERROR\n");
    else
    {
        printf("enter your sequence> ");
        for (int i=0; i<N; i++)
        {
            if (!scanf("%d", &k)) printf("INPUT ERROR\n");
            else
                if (is_square(k)) printf("%d ", k);
        }
    }
    return(0);
}
示例#10
0
int main(void)
{
    int x;

    printf("1つの自然数を入力してください:");
    scanf("%d",&x);

    if(is_square(x)){
        printf("%d は平方数です\n",x);
        printf("%d は %d の2乗です\n",x,square_number(x));
    }
    else{
        printf("%d は平方数ではありません\n",x);
    }   
    return 0;
}
示例#11
0
int main()
{
  std::vector<long> sums[2];
  std::vector<long> counters[2];
  sums[0].resize (bound, 0);
  counters[0].resize (bound, 0);
  counters[0][0] = 1;
  long result = 0;

  for (int i = 0; i < n_digits; ++i)
    {
      std::vector<long> & source = sums[i % 2];
      std::vector<long> & dest = sums[(i + 1) % 2];

      std::vector<long> & c_source = counters[i % 2];
      std::vector<long> & c_dest = counters[(i + 1) % 2];

      dest.clear();
      dest.resize(bound, 0);
      c_dest.clear();
      c_dest.resize(bound, 0);

      for (int s_squares = 0; s_squares < bound; ++s_squares)
        {
          long sum = source[s_squares];
          long n_numbers = c_source[s_squares];
          if (n_numbers == 0)
            {
              continue;
            }
          for (int digit = 0; digit < 10; ++digit)
            {
              long n_sum = (sum * 10 + digit * n_numbers) % mod;
              int n_s_sum = s_squares + digit * digit;
              if (is_square (n_s_sum))
                {
                  result = (result + n_sum) % mod;
                }
              dest[n_s_sum] += n_sum;
              c_dest[n_s_sum] += n_numbers;
            }
          c_dest[0] = 0;
        }
    }
  std::cout << result << std::endl;
  return 0;
}
int main(){
	pe::PrimeSieve<LIMIT> primes;
	for(int i = 1; i < LIMIT; i += 2){
		bool found = false;
		if(!primes[i]){
			for(int j = 0; j < primes.size() && !found; j++){
				if(primes[j] && is_square((i - j) / 2)){
					found = true;
					break;
				}
			}
		}
		if(!found && !primes[i]){
			std::cout << i << std::endl;
			break;
		}
	}
	return 0;
}
示例#13
0
文件: 141.cpp 项目: wxv/PyPE
int main()
{
    long long s = 0;
    for (long long d=1; d<int(sqrt(LIMIT)); d++)
    {
        for (int r=d-1; r>=1; r--)
        {
            long long n = d*d*d/r + r;
            if (n >= LIMIT || d/r > RATIO_LIMIT) break;
            if (d*d*d % r == 0 && is_square(n))
            {
                s += n;
                std::cout << d << '\t' << r << '\t' << float(d)/r << '\t' << sqrt(n) << std::endl;
            }
        }
    }
    std::cout << s << std::endl;
    return 0;
}
示例#14
0
int main(int argc, char **argv) {
  int N, j, num_odd;

  if (argc < 2)
    printf("Usage: %s N=%d\n", argv[0], N = 10000);
  else
    N = atoi(argv[1]);

  init_period_func();

  num_odd = 0;
  for (j = 2; j <= N; j++)
    if (!is_square(j) && period(j) % 2 == 1)
      num_odd++;

  printf("Number of numbers with odd period for N <= %d: %d\n", N, num_odd);

  free(nums);
  return 0;
}
示例#15
0
int main(int argc, char ** argv)
{
	INT d, x, j, sqrt_d;
	INT max_x, max_d;
	
	max_d = 0;
	max_x = 0;
	for(d = 2; d <= 1000; d++)
	{
		if(is_square(d))
			continue;
		
		for(j = 1; j > 0; j++)
		{
			if(is_valid_solution(d, d * j - 1))
			{
				x = d * j - 1;
				break;
			}
			if(is_valid_solution(d, d * j + 1))
			{
				x = d * j + 1;
				break;
			}
		}
		
		printf("%Ld ^ 2 - %Ld * %Ld ^ 2 == 1\n", x, d, dx_to_y(d, x));
		
		if(max_x < x)
		{
			max_x = x;
			max_d = d;
		}
	}
	
	printf("Largest minimal x for x^2-D*y^2=1 for 1 <= D <= 1000: %Ld\n", max_x);
	
	return 0;
}
示例#16
0
int main(void)
{
  char *sieve = prime_sieve(N);
  unsigned *primes = malloc(sizeof(unsigned) * N);
  unsigned i, j = 0;

  for (i = 0; i < N; i++) {
    if (!sieve[i]) {
      primes[j++] = i;
    }
  }
  primes[j] = 0;

  for (i = 3; i < N; i += 2) {
    if (!sieve[i]) {
      /* skip if i is prime */
      continue;
    }
    for (j = 0; primes[j]; j++) {
      unsigned s;

      if (primes[j] > i) {
        printf("%u\n", i);
        goto FINISH;
      }

      s = (i - primes[j])/2;
      if (is_square(s)) {
        break;
      }
    }
  }
FINISH:
  free(sieve);
  free(primes);

  return 0;
}
示例#17
0
void NRooks2D::set_bundle_size(int bundleSize) {
    assert( is_square(bundleSize) &&
        "The number of samples in a bundle must be a square." );
    bundleSize_ = bundleSize;
}
示例#18
0
int print_properties_num(longnum num)
{
	printf("%llu:\nprime factors: ", num);
	print_prime_factors(num);
	printf("\n");

	if ( is_abundant(num) ) printf(" abundant");
	if ( is_amicable(num) ) printf(" amicable");
	if ( is_apocalyptic_power(num) ) printf(" apocalyptic_power");
	if ( is_aspiring(num) ) printf(" aspiring");
	if ( is_automorphic(num) ) printf(" automorphic");
	if ( is_cake(num) ) printf(" cake");
	if ( is_carmichael(num) ) printf(" carmichael");
	if ( is_catalan(num) ) printf(" catalan");
	if ( is_composite(num) ) printf(" composite");
	if ( is_compositorial(num) ) printf(" compositorial");
	if ( is_cube(num) ) printf(" cube");
	if ( is_deficient(num) ) printf(" deficient");
	if ( is_easy_to_remember(num) ) printf(" easy_to_remember");
	if ( is_ecci1(num) ) printf(" ecci1");
	if ( is_ecci2(num) ) printf(" ecci2");
	if ( is_even(num) ) printf(" even");
	if ( is_evil(num) ) printf(" evil");
	if ( is_factorial(num) ) printf(" factorial");
	if ( is_fermat(num) ) printf(" fermat");
	if ( is_fibonacci(num) ) printf(" fibonacci");
	if ( is_google(num) ) printf(" google");
	if ( is_happy(num) ) printf(" happy");
	if ( is_hungry(num) ) printf(" hungry");
	if ( is_hypotenuse(num) ) printf(" hypotenuse");
	if ( is_lazy_caterer(num) ) printf(" lazy_caterer");
	if ( is_lucky(num) ) printf(" lucky");
	if ( is_mersenne_prime(num) ) printf(" mersenne_prime");
	if ( is_mersenne(num) ) printf(" mersenne");
	if ( is_narcissistic(num) ) printf(" narcissistic");
	if ( is_odd(num) ) printf(" odd");
	if ( is_odious(num) ) printf(" odious");
	if ( is_palindrome(num) ) printf(" palindrome");
	if ( is_palindromic_prime(num) ) printf(" palindromic_prime");
	if ( is_parasite(num) ) printf(" parasite");
	if ( is_pentagonal(num) ) printf(" pentagonal");
	if ( is_perfect(num) ) printf(" perfect");
	if ( is_persistent(num) ) printf(" persistent");
	if ( is_power_of_2(num) ) printf(" power_of_2");
	if ( is_powerful(num) ) printf(" powerful");
	if ( is_practical(num) ) printf(" practical");
	if ( is_prime(num) ) printf(" prime");
	if ( is_primorial(num) ) printf(" primorial");
	if ( is_product_perfect(num) ) printf(" product_perfect");
	if ( is_pronic(num) ) printf(" pronic");
	if ( is_repdigit(num) ) printf(" repdigit");
	if ( is_repunit(num) ) printf(" repunit");
	if ( is_smith(num) ) printf(" smith");
	if ( is_sociable(num) ) printf(" sociable");
	if ( is_square_free(num) ) printf(" square_free");
	if ( is_square(num) ) printf(" square");
	if ( is_tetrahedral(num) ) printf(" tetrahedral");
	if ( is_triangular(num) ) printf(" triangular");
	if ( is_twin(num) ) printf(" twin");
	if ( is_ulam(num) ) printf(" ulam");
	if ( is_undulating(num) ) printf(" undulating");
	if ( is_untouchable(num) ) printf(" untouchable");
	if ( is_vampire(num) ) printf(" vampire");
	if ( is_weird(num) ) printf(" weird");

	printf("\n\n");
	return 0;
}
示例#19
0
void Matrix::eig_sym(Matrix* U, Matrix* L) {
	if(!is_square()) throw std::runtime_error("Matrix must be square");
	U->init(height,width);
	L->init(1,width);
	matrix_eigSym2_float(data, U->data, L->data, width);
}
示例#20
0
Matrix Matrix::inv() {
	if(!is_square()) throw std::runtime_error("Matrix must be square");
	Matrix m(height, width);
	matrix_inv2_float(m.data, data, height);
	return m;
}
示例#21
0
int main(int argc, char *argv[])
{
//	int N = atoi(argv[1]);
        int B = atoi(argv[2]);
//      int P = atoi(argv[3]);
//      int C = atoi(argv[4]);
        int id = atoi(argv[5]);

        //Main mq
        mqd_t qdes;

        char  qname[] = "/mailbox1_srajguru";

        mode_t mode = S_IRUSR | S_IWUSR;
        struct mq_attr attr;

        attr.mq_maxmsg  = B;
        attr.mq_msgsize = sizeof(int);
        attr.mq_flags   = 0;

        qdes  = mq_open(qname, O_RDWR | O_CREAT, mode, &attr);
        if (qdes == -1 ) {
                perror("mq_open() failed");
                exit(1);
        }

        //Cons mq - communicates a counter to limit items consumed
        mqd_t consmq;

        char  consqname[] = "/consmq";

        mode_t modecmq = S_IRUSR | S_IWUSR;
        struct mq_attr cmqattr;

        cmqattr.mq_maxmsg  = 1;
        cmqattr.mq_msgsize = sizeof(int);
        cmqattr.mq_flags   = 0;            /* a blocking queue  */

        consmq  = mq_open(consqname, O_RDWR | O_CREAT, modecmq, &cmqattr);
        if (consmq == -1 ) {
                perror("mq_open() failed");
                exit(1);
        }

        int conscount;

        while(1)
        {
                mq_receive(consmq, (char *) &conscount, sizeof(int), 0);
                if(conscount!=0)
                {
                //Decrement counter if all of the numbers produced still haven't been consumed
                 conscount--;
                 mq_send(consmq, (char *)&conscount, sizeof(int), 0);

                 int number;
		
                 if ((mq_receive(qdes, (char *) &number, sizeof(int), 0)) == -1)
                 {
                   perror("mq_receive() failed");

           } else {

                //Check if the number received meets the print conditions as mentioned in the manual
                if(is_square(number) == 1)
                {
                    int res = sqrt(number);
                    printf("%i %i %i\n", id, number, res);
                }

                }
                }

//Last number to be consumed
else
{
 mq_send(consmq, (char *)&conscount, sizeof(int), 0);
 break;
}
}

if (mq_close(qdes) == -1) {
  perror("mq_close() failed");
  exit(2);
}

if (mq_close(consmq) == -1) {
  perror("mq_close() failed");
  exit(2);
}

return 0;
}