///Adding Loadfactors to Load 'Beam2dThermalAction' for FireLoadPattern [-BEGIN-]:by L.J&P.K(university of Edinburgh)-07-MAY-2012-/// void Beam3dThermalAction::setfactors(int value, double loadFactor2, double loadFactor3, double loadFactor4, double loadFactor5, double loadFactor6, double loadFactor7, double loadFactor8, double loadFactor9) { indicator=value; //1 indicates fireloadpattern was called Factor2=loadFactor2; Factor3=loadFactor3; Factor4=loadFactor4; Factor5=loadFactor5; Factor6=loadFactor6; Factor7=loadFactor7; Factor8=loadFactor8; Factor9=loadFactor9; Factor10=loadFactor9; //Not Updated, Liming,2013 //opserr << "beam2d loadfactor2\n"; //opserr << loadFactor2; factors(0) = indicator; factors(1) = Factor2; factors(2) = Factor3; factors(3) = Factor4; factors(4) = Factor5; factors(5) = Factor6; factors(6) = Factor7; factors(7) = Factor8; factors(8) = Factor9; factors(9) = Factor10; //opserr << "Beam2dTemperatureLoad set factors: "; }
void remove_negative_exponents(void) { int h, i, j, k, n; h = tos; factors(A); factors(B); n = tos - h; // find the smallest exponent j = 0; for (i = 0; i < n; i++) { p1 = stack[h + i]; if (car(p1) != symbol(POWER)) continue; if (cadr(p1) != X) continue; push(caddr(p1)); k = pop_integer(); if (k == (int) 0x80000000) continue; if (k < j) j = k; } tos = h; if (j == 0) return; // A = A / X^j push(A); push(X); push_integer(-j); power(); multiply(); A = pop(); // B = B / X^j push(B); push(X); push_integer(-j); power(); multiply(); B = pop(); }
struct PMultiStageDef* build_auto_ratios(int fsin, int fsout, double tol) { int L = 0; int M = 0; double rat = (double) fsin / fsout; find_ratio(rat, tol * rat, &M, &L); int nbL = MAX_FACTORS; int* LL = malloc(nbL * sizeof(int)); if (factors(L, LL, &nbL) != 1) { free(LL); printf("WARNING: too many factors for %i !\n", L); return NULL; } int nbM = MAX_FACTORS; int* MM = malloc(nbM * sizeof(int)); if (factors(M, MM, &nbM) != 1) { free(MM); printf("ERROR: too many factors for %i !\n", M); return NULL; } if (nbL < nbM) { memmove(&LL[nbM - nbL], LL, nbL * sizeof(int)); for (int i = 0; i < (nbM - nbL); i++) LL[i] = 1; nbL = nbM; } if (nbM < nbL) { for (int i = nbM; i < nbL; i++) MM[i] = 1; nbM = nbL; } struct PMultiStageDef* pdef = malloc(sizeof(struct PMultiStageDef)); pdef->nb_stages = nbL; pdef->L = malloc(2 * nbL * sizeof(int)); pdef->M = &pdef->L[nbL]; for (int s = 0; s < nbL; s++) { pdef->L[s] = LL[s]; pdef->M[s] = MM[s]; } free(LL); free(MM); reorder_stages(pdef); return pdef; }
std::array<Size, 2> StructuredGrid2D::computeBlockDims(bool stripPartitioning) const { if(stripPartitioning) return std::array<Size, 2>({(Size)_comm->nProcs(), 1}); Size i = 2, num = _comm->nProcs(); std::deque<Size> factors(1, 1); while(i <= num) { if(num % i) ++i; else { factors.emplace_front(i); num /= i; } } while(factors.size() > 2) { std::sort(factors.begin(), factors.end()); factors[1] *= factors[0]; factors.pop_front(); } std::array<Size, 2> result; result[0] = factors[0]; result[1] = factors[1]; return result; }
int main(void) { assert(triangleN(7) == 28); assert(factors(28) == 6); std::cout << problem12() << std::endl; }
inline std::vector<std::size_t> get_factors(std::size_t nlocals, std::vector<std::size_t> & primes) { if(primes.size() == 0) { throw "..."; } typedef std::vector<std::size_t> vector_type; typedef vector_type::reverse_iterator reverse_iterator; vector_type factors(primes.size()); for(reverse_iterator c = factors.rbegin(), p = primes.rbegin(); c != factors.rend(); ++c, ++p) { *c = 0; while((nlocals % *p) == 0) { ++(*c); nlocals /= *p; } } if(nlocals != 1 ) { throw "..."; } return factors; }
//--------------------------------------------------------------------------- int AntSolver2::pickValue( int variable, vector< vector< double > > &valuesScore ) { int domainSize = problem->getDomainList()->getDomainSize( variable ); int numVars = problem->getNumVars(); vector< double > factors( domainSize ); double sumFactors = 0; for ( int i = 0; i < domainSize; i++ ) { double trailFactor = getTrailFactor( variable, i ); double qualityFactor = valuesScore[variable][i]; factors[i] = pow( trailFactor, alpha ) * pow( qualityFactor, beta ); sumFactors += factors[i]; } if ( sumFactors == 0 ) { sumFactors = domainSize; factors.assign( domainSize, 1 ); } int value = (int)Random::s_pick( factors, sumFactors ); return value; }
int main (int argc, char** argv) { // parse the program arguments options in_options = options(); CHECK(parse_arguments(argc, argv, in_options)); // parse the input graph std::unordered_map<uint64_t,cell> graph; CHECK(parse_graph(in_options, graph)); //CHECK(validate_parser(in_options, graph)); // factor the number of partitions std::vector<uint64_t> factors(0); CHECK(factor(in_options, factors)); CHECK(validate_factors(in_options, factors)); // partition! CHECK(partition(in_options, graph, factors)); // write partitions CHECK(write_partitions(in_options, graph)); CHECK(do_cleanup(graph)); return 0; }
void calculateBezier(std::vector<Point3D>& points) { Point3D p; int n = points.size() - 1; std::vector<int> factors(points.size()); double t, b; computeFactors(factors); t = 0.00; for(int i = 0; t < 1.0; ++i) { p.x = p.y = p.z = 0; for (int j = 0; j < points.size(); ++j) { if (j == 0) { b = factors[j] * pow(1 - t, n); } else if (j == n) { b = factors[j] * pow(t, n); } else { b = factors[j] * pow(t, j) * pow(1-t, n-j); } p.x += b * points[j].x; p.y += b * points[j].y; p.z += b * points[j].z; } bezierPoints.push_back(p); t += 0.01; if (t > 1.0) break; } }
int64_t S2_hard(int64_t x, int64_t y, int64_t z, int64_t c, int64_t s2_hard_approx, int threads) { #ifdef HAVE_MPI if (mpi_num_procs() > 1) return S2_hard_mpi(x, y, z, c, s2_hard_approx, threads); #endif print(""); print("=== S2_hard(x, y) ==="); print("Computation of the hard special leaves"); print(x, y, c, threads); double time = get_wtime(); FactorTable<uint16_t> factors(y, threads); int64_t max_prime = z / isqrt(y); vector<int32_t> primes = generate_primes(max_prime); int64_t s2_hard = S2_hard_OpenMP_master((intfast64_t) x, y, z, c, (intfast64_t) s2_hard_approx, primes, factors, threads); print("S2_hard", s2_hard, time); return s2_hard; }
int main(void){ memset(sieve,1,sizeof(sieve)); sieve[0] = sieve[1] = 0; primes[0] = 2; for(i = 4; i < 31622; i+=2) sieve[i] = 0; for(idx=1,i = 3; i < 31622; i+=2){ if(sieve[i]){ primes[idx++] = i; if(i < 177) for(j = i*i; j < 31622; j+=i) sieve[j] = 0; } } scanf("%u",&cnum); while(cnum--){ scanf("%u %u\n",&u,&l); maxdiv = 0; for(j = u; j <= l; j++){ factors(j); if(div > maxdiv){ maxdiv = div; chosen = j; } } printf("Between %u and %u, %u has a maximum of %u divisors.\n",u,l,chosen,maxdiv); } return 0; }
std::vector< std::vector<double> > getFactors() { if(children.size() == 0) return std::vector< std::vector<double> >(1, std::vector<double>(1, factor)); std::vector< std::vector< std::vector< std::vector<double> > > > childrenFactors(children.size(), std::vector< std::vector< std::vector<double> > >(children.front().size())); for(int a = 0; a < children.size(); a++) { for(int b = 0; b < children.front().size(); b++) { childrenFactors[a][b] = children[a][b]->getFactors(); } } int width = 0, height = 0; for(int a = 0; a < children.size(); a++) height += childrenFactors[a].front().size(); for(int b = 0; b < children.front().size(); b++) width += childrenFactors.front()[b].front().size(); std::vector< std::vector<double> > factors(height, std::vector<double>(width)); int x = 0, y = 0; for(int my = 0; my < children.size(); my++) { for(int iy = 0; iy < childrenFactors[my].front().size(); iy++) { for(int mx = 0; mx < children.front().size(); mx++) { for(int ix = 0; ix < childrenFactors.front()[mx].front().size(); ix++) { factors[y][x] = childrenFactors[my][mx][iy][ix] * factor; x++; } } y++; x = 0; } } return factors; }
int main(int argc, const char * argv[]) { int number; //loop until zero is end to end the program do { printf("1. Factors \n"); printf("2. Prime Factors \n"); printf("0. Stop \n"); scanf("%d", &number); if (number == 1) { factors(); } if (number == 2) { primeFactors(); } } while (number != 0); }
std::set<T> common_factors(T N,Args ...args){ std::set<T> Int=common_factors(args...); if(Int.size()==0)return Int; std::set<T> CommonFs,MyFs=factors(N); std::set_intersection(Int.begin(),Int.end(),MyFs.begin(),MyFs.end(), std::inserter(CommonFs,CommonFs.begin())); return CommonFs; }
int problem12() { for (int n = 1; ; ++n) { const int triangle = triangleN(n); if (500 < factors(triangle)) return triangle; } }
fft_object fft_init(int N, int sgn) { fft_object obj = NULL; // Change N/2 to N-1 for longvector case int twi_len,ct,out; out = dividebyN(N); if (out == 1) { obj = (fft_object) malloc (sizeof(struct fft_set) + sizeof(fft_data)* (N-1)); obj->lf = factors(N,obj->factors); longvectorN(obj->twiddle,N,obj->factors,obj->lf); twi_len = N; obj->lt = 0; } else { int K,M; K = (int) pow(2.0,ceil(log10(N)/log10(2.0))); if (K < 2 * N - 2) { M = K * 2; } else { M = K; } obj = (fft_object) malloc (sizeof(struct fft_set) + sizeof(fft_data)* (M-1)); obj->lf = factors(M,obj->factors); longvectorN(obj->twiddle,M,obj->factors,obj->lf); obj->lt = 1; twi_len = M; } obj->N = N; obj->sgn = sgn; if (sgn == -1) { for(ct = 0; ct < twi_len;ct++) { (obj->twiddle+ct)->im = - (obj->twiddle+ct)->im; } } return obj; }
int main(void) { struct factors f; long i, max = 0; f = factors(N); for (i = 0; i < f.size; i++) { if (max < f.vector[i]) { max = f.vector[i]; } } printf("%ld\n", max); }
int main(void) { char *str = "aaabbaa"; char *s = factors(str, 3); int i; for(i=0; i<strlen(str)+1; i++) { printf("%c", s[i]); } printf("\n"); return 0; }
int main() { int n = 1; while(1) { int tr = trnum(n); if(factors(tr) > 500) { printf("%d\n", tr); break; } ++n; } return 0; }
void FNeuralNetLMBase::ReadDecompFromTxt(const string &decomptxt) { if (decomptxt == "") { cerr << "Warning: no decomposition file is set!" << endl; factors_for_word_.clear(); } else { ifstream ifs; ifs.open(decomptxt, ios::in); if (ifs.fail()) { cerr << "Unable to open " << decomptxt << endl; exit(EXIT_FAILURE); } factors_for_word_.resize(word_vocab_.size()); string line; char_separator<char> space_separator(" "); char_separator<char> tab_separator("\t"); while (getline(ifs, line)) { tokenizer<char_separator<char>> word_factors(line, tab_separator); tokenizer<char_separator<char>>::const_iterator it = word_factors.begin(); size_t w = word_vocab_.idx4type(*it); vector<size_t> &fs = factors_for_word_[w]; if (!fs.empty()) { cerr << "double defined decomposition for word " << *it << endl; exit(EXIT_FAILURE); } if (++it == word_factors.end()) { cerr << "wrong decomposition format (no tab)!" << endl; exit(EXIT_FAILURE); } tokenizer<char_separator<char>> factors(*it, tab_separator); if(++it != word_factors.end()) { cerr << "wrong decomposition format (more than one tab)!" << endl; exit(EXIT_FAILURE); } for (it = factors.begin(); it != factors.end(); ++it) { fs.push_back(factor_vocab_.idx4type(*it)); } assert(!fs.empty()); } for (size_t w = 0; w < word_vocab_.size(); w++) { if (factors_for_word_[w].empty()) { cerr << "no decomposition defined for word: " << word_vocab_.type4idx(w) << endl; exit(EXIT_FAILURE); } } } }
ll solve(const int *array, int size) { std::unordered_map<int, int> lcm; for (int fin = 0; fin < size; fin++) { int count = 1; for (int b = array[fin]; b != fin; b = array[b]) { count++; } factors(count, lcm); } ll ans = 1; for (auto &v : lcm) { ans = (ans * static_cast<ll>(std::pow(v.first, v.second))) % modulos; } return ans; }
/* main entry point */ int main(int argc, char *argv[]) { int n; if (argc < 2) { fprintf(stderr, "usage: factor number\n"); exit(EXIT_FAILURE); } n = atoi(argv[1]); if (n < 0) { fprintf(stderr, "number must be a positive integer.\n"); exit(EXIT_FAILURE); } factors(n); return 0; }
int main(){ int t, i, n, j, s, f; scanf("%d", &t); for(i=0; i<t; i++){ scanf("%d", &n); if(n<=2)n=3; for(j=n+1; ; j++){ if(!isPrime(j)){ s = digitSum(j); f = factors(j); if(s == f){ printf("%d\n", j); break; } } } } return 0; }
void PoldiSpectrumDomainFunction::poldiFunction1D( const std::vector<int> &indices, const FunctionDomain1D &domain, FunctionValues &values) const { FunctionValues localValues(domain); m_profileFunction->functionLocal(localValues.getPointerToCalculated(0), domain.getPointerAt(0), domain.size()); double chopperSlitCount = static_cast<double>(m_chopperSlitOffsets.size()); for (auto index : indices) { std::vector<double> factors(domain.size()); for (size_t i = 0; i < factors.size(); ++i) { values.addToCalculated(i, chopperSlitCount * localValues[i] * m_timeTransformer->detectorElementIntensity( domain[i], static_cast<size_t>(index))); } } }
std::vector<std::size_t> factor(std::size_t n) { std::vector<std::size_t> factors(numFactors2(n), 2); n = n >> factors.size(); std::vector<std::size_t> primes = getPossiblePrimeFactors(n); for(std::size_t i = 1; n > 1 && i < primes.size(); ++i) { std::size_t factored = n/primes[i]; while(n > 1 && factored*primes[i] == n) { factors.push_back(primes[i]); n = factored; factored /= primes[i]; } } if(n > 1) factors.push_back(n); return factors; }
std::vector<std::complex<T> > getTwiddleFactors(size_t N, bool fwd, size_t Lm1Qm1 = std::numeric_limits<size_t>::max) { std::vector<std::complex<T> > factors(std::min(N, Lm1Qm1)); if(factors.size() > 0) { factors[0] = 1; if(factors.size() > 1) { // Use high-precision multiplication of phasors. typedef std::complex<long double> HighPrecComplex; long double phase = 2*3.14159265358979323846/N; HighPrecComplex phasor(cos(phase), fwd ? -sin(phase) : sin(phase)); HighPrecComplex tmp(phasor); factors[1] = tmp; for(size_t i = 2; i < factors.size(); ++i) factors[i] = tmp = tmp * phasor; } } return factors; }
string getPermutation(int n, int k) { string result; vector<int> digits(n, 1); vector<int> factors(n, 1); // 记录阶乘结果 int i; // 初始化数字和阶乘表 for (i = 1; i < n; ++i) { digits[i] = i + 1; factors[i] = i * factors[i - 1]; } for (i = n - 1; i >= 0; --i) { // 确定第一个数字的位置 int pos = (k - 1) / factors[i]; result.push_back(digits[pos] + '0'); digits.erase(digits.begin() + pos); k -= (pos * factors[i]); } return result; }
int nthSuperUglyNumber(int n, vector<int>& primes) { vector<int>ans(n,INT_MAX); ans[0]=1; if(n==1) return 1; int m=primes.size(); vector<int> indexs(m,1); vector<int> factors(primes.begin(),primes.end()); for(int i=1;i<n;i++) { for(int j=0;j<m;j++) ans[i]=min(ans[i],factors[j]); for(int j=0;j<m;j++) { if(ans[i]==factors[j]) { factors[j]=primes[j]*ans[indexs[j]]; indexs[j]++; } } } return ans[n-1]; }
std::set<T> common_factors(T N){return factors(N);}
bool is_prime(T Num){ std::set<T> facs=factors(Num); return facs.size()==2; }