Пример #1
0
inline bool is_amicable(const T& a, T& b)
{
    std::vector<T> a_div{get_divisors(a)};
    b = std::accumulate(a_div.begin(), a_div.end(), T{0});
    std::vector<T> b_div{get_divisors(b)};
    long b_div_sum{std::accumulate(b_div.begin(), b_div.end(), T{0})};
    return (b>a && a==b_div_sum);
}
Пример #2
0
int main(int argc, char **argv){
	if (argc == 2){
		std::string aString = argv[1];
		if (isInt(aString)){
			int a = toInt(aString);
			std::vector<int> vector_divisors;
			get_divisors(vector_divisors, a);
			std::cout << "Divisors of " << a << ":\n\t";
			print_vector(vector_divisors);
			std::vector<int> vector_factors;
			std::cout << "Factors of " << a << ":\n\t";
			get_factors(vector_factors, a);
			print_vector(vector_factors);
		}
	}
	else{
		std::cout << "It need one integer number to work" << std::endl;
	}
	return 0;
}
Пример #3
0
void CLProgramGenerator::InitRuntimeParameters() {
  globalDim = new std::vector<unsigned int>(no_dims, 1);
  localDim = new std::vector<unsigned int>(no_dims, 1);
  std::vector<unsigned int>& globalDim = *CLSmith::globalDim;
  std::vector<unsigned int>& localDim = *CLSmith::localDim;
  std::vector<unsigned int> chosen_div;
  std::vector<unsigned int> divisors;
  for (unsigned int i = 0; i < no_dims; i++) {
    globalDim[i] = rnd_upto(std::min(max_thr_per_dim, max_threads / noThreads)) + 1;
    noThreads *= globalDim[i];
  }
  unsigned int curr_thr_p_grp;
  do {
    curr_thr_p_grp = 1;
    for (unsigned int i = 0; i < no_dims; i++) {
      get_divisors(globalDim[i], &divisors);
      localDim[i] = divisors[rnd_upto(divisors.size())];
      curr_thr_p_grp *= localDim[i];
    }
  } while (curr_thr_p_grp > max_threads_per_group);
  for (unsigned int i = 0; i < no_dims; i++)
    noGroups *= globalDim[i] / localDim[i];
}