int main() { int n; int m; read(max); while ((max <= 1)||(max >=150)) read(max); n=2; while (n <= max) { a[n]=true; n++; } n=4; while (n <= max) { if (divisor(2,n)) a[n]=false; else { m=3; while ((m*m) <= n) if (divisor(m,n)) { a[n]=false; m=n; } else m=m+2; } n++; } n=2; while (n <= max ){ if (a[n]) print(n); else ; n++; } }
void exibir_pessoa(struct cadastro pessoa, int id) { divisor(); printf("#ID: %i\n", id); printf("Nome: %s\n", pessoa.nome); printf("Idade: %s", pessoa.idade); // printf("RG: %s\n", pessoa.rg); // printf("CPF: %s\n", pessoa.cpf); // printf("UF: %s\n", pessoa.uf); // printf("Endereco: %s\n", pessoa.endereco); // printf("Municipio: %s\n", pessoa.municipio); divisor(); }
std::string CRC::runCRC(std::string message) { std::string messageString = message; //Original besked std::string poly = "111010101"; //Polynomial division std::string aug = messageString + "00000000"; //Padded besked, bliver senere til remainder indtil denne bliver checksummen std::string tempRemainderString; std::string tempAug; std::bitset<9> divisor(poly); //Bit divisor std::bitset<9> tempRemainder; //holder til besked while (aug.size() > 8) //imens beskeden er større end 8 (size of checksum!) { std::bitset<9> remainder(std::string(aug, 0, 9)); //Tag de 9 første bit if (remainder[8] == 1) //Hvis det første bit er sat (!!! Dette læses bitvist, fra højre mod venstre!!!) { tempRemainder = remainder ^ divisor; //Udfør polynomial division via "xor" tempRemainderString = tempRemainder.to_string(); tempAug = ""; tempAug.append(aug, 9, aug.size()); aug = tempRemainderString + tempAug; //Saml resultat og resterende besked } else //Hvis det første bit ikke er sat, så skal beskeden shiftes mod venstre { aug.erase(aug.begin()); //Sletter det første bit i beskeden } } //std::cout << "checksum: " << aug << std::endl; //Output checksum return aug; }
void main() { int m,n; printf("Please enter m,n :"); scanf("%d,%d",&m,&n); printf("%d和%d的最大公约数为%d,最小公倍数为%d\n",m,n,divisor(m,n),multiple(m,n)); }
// n 以上の最小の素数 (>=3) を返す。 int NextPrime(int n){ if(n <3) n = 3; if(n%2 == 0 ) n++; while(n > divisor(n)) n = n+2; return n; }
int main(){ long i; unsigned long tri = 0; for(i = 1;;i++){ tri = tri + i; //printf("%lu, %ld %d\n", tri, i, divisor(tri)); if(divisor(tri) >= 501){ printf("---------------------------------\n"); printf("%lu, %ld %d\n", tri, i, divisor(tri)); break; } if(i % 100 == 0) printf("%lu, %ld %d\n", tri, i, divisor(tri)); } }
void SumFunc::execute() { ComValue vallist(stack_arg(0)); reset_stack(); if (vallist.is_type(ComValue::ArrayType)) { AttributeValueList* avl = vallist.array_val(); AddFunc addfunc(comterp()); push_stack(ComValue::zeroval()); Iterator it; int count = 0; for (avl->First(it); !avl->Done(it); avl->Next(it)) { count++; push_stack(*avl->GetAttrVal(it)); addfunc.exec(2,0); } if (_meanfunc) { DivFunc divfunc(comterp()); ComValue divisor(count, ComValue::IntType); push_stack(divisor); divfunc.exec(2,0); } } else { push_stack(vallist); } }
int divisor(int a, int b) { if (a % b) return divisor(b, a % b); return b; }
bool isPrime(T val) { bool prime = true; if (val < 2) { return false; } else if (val == 2) { return true; } else if (val % 2 == 0) { return false; } else { T divisor(3); double dval = static_cast<double>(val); T upperLimit = static_cast<T>(std::sqrt(dval) + 1); while (divisor <= upperLimit) { if (val % divisor == 0) { prime = false; break; } divisor += 2; } } return prime; }
bignum exponent(const bignum &base_value, const bignum &power, int precision) { if (base_value.getBase() != power.getBase()) return exponent(base_value, power.getConverted(power.getBase())); bignum one(1); one.setBase(base_value.getBase()); one.setPositive(); if (power.isZero()) return one; //if the power is negative, return 1/solution if (power.isNegative()) return one / exponent(base_value, power.absolute()); if (power.getDecimalCount() > 0) { if (power < 1) { bignum modified_power(power); modified_power.leftShift(power.getDecimalCount()); bignum divisor(1); divisor.setBase(power.getBase()); divisor.leftShift(power.getDecimalCount()); bignum gcf(greatestCommonFactor(modified_power, divisor)); modified_power /= gcf; divisor /= gcf; bignum divisor_root_of_base = jep::root(divisor, base_value, precision); return exponent(divisor_root_of_base, modified_power).getRoundedAllDigits(ONES_PLACE - precision); } else { bignum power_decimal = power % 1; bignum power_int = power.getRoundedDown(ONES_PLACE); return exponent(base_value, power_int, precision) * exponent(base_value, power_decimal, precision); } } bignum counter = power.absolute(); bignum temp(base_value); //n^0 always returns 1 if (power.isZero()) return one; while (counter > one) { temp *= base_value; counter--; } return temp; }
BigInt& BigInt::operator/=(const BigInt& that) { if (that.isZero()) throw std::invalid_argument("division by zero"); else if (positive && *this < that) return *this = zero; bool signsDiffer = positive != that.positive; BigInt dividend(*this); BigInt divisor(that); size_t shift = dividend.size() - divisor.size(); std::vector<bool> binaryDigits; dividend.positive = divisor.positive = true; divisor <<= shift; while (divisor > dividend) { divisor >>= 1; shift--; } while (shift) { if (divisor <= dividend) { dividend -= divisor; binaryDigits.push_back(true); } else binaryDigits.push_back(false); --shift; divisor >>= 1; } if (dividend >= divisor) { binaryDigits.push_back(true); dividend -= divisor; } else binaryDigits.push_back(false); std::reverse(binaryDigits.begin(), binaryDigits.end()); *this = BigInt(BigInt::binaryToWords(binaryDigits), positive == that.positive); if (signsDiffer && !dividend.isZero()) *this -= 1; trim(); return *this; }
PassRefPtr<FilterEffect> SVGFEConvolveMatrixElement::build(SVGFilterBuilder* filterBuilder) { FilterEffect* input1 = filterBuilder->getEffectById(in1()); if (!input1) return 0; Vector<float> kernelMatrixValues; SVGNumberList* numbers = kernelMatrix(); ExceptionCode ec = 0; int numberOfItems = numbers->numberOfItems(); for (int i = 0; i < numberOfItems; ++i) kernelMatrixValues.append(numbers->getItem(i, ec)); int orderXValue = orderX(); int orderYValue = orderY(); if (!hasAttribute(SVGNames::orderAttr)) { orderXValue = 3; orderYValue = 3; } // The spec says this is a requirement, and should bail out if fails if (orderXValue * orderYValue != numberOfItems) return 0; int targetXValue = targetX(); int targetYValue = targetY(); if (hasAttribute(SVGNames::targetXAttr) && (targetXValue < 0 || targetXValue >= orderXValue)) return 0; // The spec says the default value is: targetX = floor ( orderX / 2 )) if (!hasAttribute(SVGNames::targetXAttr)) targetXValue = static_cast<int>(floorf(orderXValue / 2)); if (hasAttribute(SVGNames::targetYAttr) && (targetYValue < 0 || targetYValue >= orderYValue)) return 0; // The spec says the default value is: targetY = floor ( orderY / 2 )) if (!hasAttribute(SVGNames::targetYAttr)) targetYValue = static_cast<int>(floorf(orderYValue / 2)); float divisorValue = divisor(); if (hasAttribute(SVGNames::divisorAttr) && !divisorValue) return 0; if (!hasAttribute(SVGNames::divisorAttr)) { for (int i = 0; i < numberOfItems; ++i) divisorValue += kernelMatrixValues[i]; if (!divisorValue) divisorValue = 1; } RefPtr<FilterEffect> effect = FEConvolveMatrix::create( IntSize(orderXValue, orderYValue), divisorValue, bias(), IntPoint(targetXValue, targetYValue), static_cast<EdgeModeType>(edgeMode()), FloatPoint(kernelUnitLengthX(), kernelUnitLengthX()), preserveAlpha(), kernelMatrixValues); effect->inputEffects().append(input1); return effect.release(); }
void oblique::set_particle(){ arma::mat y_temp=arma::randn(n,p), temp, divisor=arma::eye(p,p); int k; for(k=0;k<p;k++){ temp=y_temp.col(k); divisor(k,k)=arma::norm(temp,"fro"); } Y=y_temp*(divisor.i()); arma::mat velocity_temp=arma::randn(n,p); //psedo gradient as velocity; evalGradient(velocity_temp,"particleSwarm"); }
//second argument unused arma::mat oblique::retract(double stepSize, std::string method, bool first){ Yt=Y+stepSize*descD; arma::mat temp, divisor=arma::eye(p,p); int k; for(k=0;k<p;k++){ temp=Yt.col(k); divisor(k,k)=arma::norm(temp,"fro"); } Yt=Yt*(divisor.i()); return Yt; }
// Division: template <typename T> Measurement<T> &Measurement<T>::operator /= (const Measurement<T> &measurement) { Measurement divisor(measurement); if(divisor.invert() != 0) { std::cerr << "Error (Measurement): Cannot divide measurements; divisor is zero." << std::endl; return *this; } *this *= divisor; return *this; }
int main() { int t,x,n,y,i; scanf("%d",&t); for (i = 1; i <= t ; i++) { scanf("%d",&n); scanf("%d",&x); scanf("%d",&y); divisor(n,x,y); printf("\n"); } return 0; }
BigInt BigInt::operator%(const BigInt& second) { BigInt dividend(this); BigInt divisor(second); int startM = dividend.getMagnitude() - divisor.getMagnitude(); divisor.times10ToN(startM); for(int i=startM; i >= 0; --i) { while(absCmp(dividend, divisor)){ dividend -= divisor; } divisor.times10ToN(-1); } return dividend; }
int main(void) { int a, b, c, d; printf("Please input two numbers "); scanf("%d %d", &a, &b); c = divisor(a, b); printf("The max divisor is %d\n", c); a /= c; b /= c; d = a * b * c; printf("The min multiple is %d\n", d); return 0; }
char menu() { int tela; printf("\n\nMENU\n\n"); printf("Digite:\n"); printf("1 -> Cadastrar Pessoas\n"); printf("2 -> Listar Pessoas\n"); printf("3 -> Atualizar uma Pessoa\n"); printf("4 -> Apagar uma Pessoa:\n"); printf("5 -> SAIR\n\n"); scanf("%d", &tela); divisor(); return tela; }
const BigInt operator /(const BigInt& amount1, const BigInt& amount2) { // magn = magnificent; BigInt quotient, magn(amount2), dividend(amount1), divisor(amount2); dividend.sign = divisor.sign = 0; if(dividend < divisor) return BigInt(0); if(dividend > divisor) magn = magn.leftShift(dividend.length - divisor.length); //if(dividend < magn) // magn = magn.rightShift(); // magn = magn/10; if(dividend >= magn) quotient.length = amount1.length - amount2.length + 1; else{ quotient.length = amount1.length - amount2.length; magn = magn.rightShift(); // magn = magn/10; } quotient.digit = new int[quotient.length]; for(int i = 0 ; i < quotient.length ; i++) quotient.digit[i] = 0; int index(0); while(dividend >= divisor){ while(dividend >= magn) { quotient.digit[index]++; dividend = dividend - magn; } magn = magn.rightShift(); index++; } if(amount1.getSign() == amount2.getSign()) return BigInt( quotient.digit , quotient.length, quotient.sign); else return BigInt( quotient.digit , quotient.length, !quotient.sign); }
//! Division of two gfx (local help function) gfx divgfx(const gfx &c, const gfx &g) { int q = c.get_size(); gfx temp = c; int tempdegree = temp.get_true_degree(); int gdegree = g.get_true_degree(); int degreedif = tempdegree - gdegree; gfx m(q,degreedif), divisor(q); for (int i=0; i<c.get_degree(); i++) { m[degreedif] = temp[tempdegree]/g[gdegree]; divisor.set_degree(degreedif); divisor.clear(); divisor[degreedif] = m[degreedif]; temp -= divisor*g; tempdegree = temp.get_true_degree(); degreedif = tempdegree - gdegree; if ( (degreedif<0) || (temp.get_true_degree()==0 && temp[0] == gf(q,-1) ) ) { break; } } return m; }
void precalculation() { dis[0]=1; dis[1]=1; dis[2]=2; result[0]=0; result[1]=1; result[2]=2; co1=2; for(x=3;x<=64726;x++){ d=divisor(dis[x-1]); dis[x]=dis[x-1]+d; for(j=dis[x-1]+1;j<dis[x];j++) result[j]=co1; co1++; result[dis[x]]=co1; } }
//! Modulo function of two gfx (local help function) gfx modgfx(const gfx &a, const gfx &b) { int q = a.get_size(); gfx temp = a; int tempdegree = temp.get_true_degree(); int bdegree = b.get_true_degree(); int degreedif = a.get_true_degree() - b.get_true_degree(); gfx m(q,degreedif), divisor(q); for (int i=0; i<a.get_degree(); i++) { m[degreedif] = temp[tempdegree]/b[bdegree]; divisor.set_degree(degreedif); divisor.clear(); divisor[degreedif] = m[degreedif]; temp -= divisor*b; // Bug-fixed. Used to be: temp -= divisor*a; tempdegree = temp.get_true_degree(); degreedif = temp.get_true_degree() - bdegree; if ( (degreedif<0) || (temp.get_true_degree()==0 && temp[0] == gf(q,-1) ) ) { break; } } return temp; }
void RectangularMatrixTest::multiplyDivide() { Matrix2 matrix(Vector2(1.0f, 2.0f), Vector2(3.0f, 4.0f)); Matrix2 multiplied(Vector2(-1.5f, -3.0f), Vector2(-4.5f, -6.0f)); CORRADE_COMPARE(matrix*-1.5f, multiplied); CORRADE_COMPARE(-1.5f*matrix, multiplied); CORRADE_COMPARE(multiplied/-1.5f, matrix); Math::RectangularMatrix<1, 1, Byte> matrixChar(32); Math::RectangularMatrix<1, 1, Byte> multipliedChar(-48); CORRADE_COMPARE(matrixChar*-1.5f, multipliedChar); CORRADE_COMPARE(multipliedChar/-1.5f, matrixChar); CORRADE_COMPARE(-1.5f*matrixChar, multipliedChar); /* Divide vector with number and inverse */ Matrix2 divisor(Vector2( 1.0f, 2.0f), Vector2(-4.0f, 8.0f)); Matrix2 result(Vector2( 1.0f, 0.5f), Vector2(-0.25f, 0.125f)); CORRADE_COMPARE(1.0f/divisor, result); CORRADE_COMPARE(-1550.0f/multipliedChar, matrixChar); }
int musicDiv( int nota ){ return divisor(notes_frequency[nota]); }
struct fChannelEstimationStruct fChannelEstimation( vector<vector<complex<double> > > symbolsIn, vector<int> goldseq, int numberOfDesiredPaths, double phi) { //function works only for single path and single antenna right now struct fChannelEstimationStruct channelEstimation; int length = symbolsIn[0].size(); // estimate delay int estimatedDelay; double maxAutoCorr = 0.0; channelEstimation.beta_estimate.resize(numberOfDesiredPaths, complex<double>(0.0, 0.0)); channelEstimation.delay_estimate.resize(numberOfDesiredPaths, 0); for (int delay = 0; delay < goldseq.size(); delay++) { complex<double> autoCorr(0.0, 0.0); for (int i = 0; i < goldseq.size(); i++) { complex<double> cChip((double)goldseq[i], 0.0); autoCorr += cChip * symbolsIn[0][(i + delay) % length]; } // keep a list of the abs-greatest beta_values and according delays if (abs(autoCorr) > abs(channelEstimation.beta_estimate[ numberOfDesiredPaths-1])) { channelEstimation.beta_estimate[numberOfDesiredPaths-1] = autoCorr; channelEstimation.delay_estimate[numberOfDesiredPaths-1] = delay; for (int i = numberOfDesiredPaths-2; i >= 0; i--) { if (abs(channelEstimation.beta_estimate[i]) < abs(channelEstimation.beta_estimate[i+1])) { // swap complex<double> tmp = channelEstimation.beta_estimate[i]; int tmp2 = channelEstimation.delay_estimate[i]; channelEstimation.beta_estimate[i] = channelEstimation.beta_estimate[i+1]; channelEstimation.delay_estimate[i] = channelEstimation.delay_estimate[i+1]; channelEstimation.beta_estimate[i+1] = tmp; channelEstimation.delay_estimate[i+1] = tmp2; } } } } // estimate beta complex<double> divisor(goldseq.size(), goldseq.size()); for (int i = 0; i < numberOfDesiredPaths; i++) channelEstimation.beta_estimate[i] /= divisor * complex<double>(cos(phi*2*3.14159/360),sin(phi*2*3.14159/360)); ; // since the frist two bits are pilot bits set on 1, the complex number should be 1+i return channelEstimation; }
int multiple(int x, int y)//求最小公倍数 { int z; z=x*y/divisor(x,y); return z; }