예제 #1
0
int main( void )
{
	SWORD a, b;
	SWORD a1, b1;
	SWORD mina = 0, minb = 0;
	FILE *IN, *OUT;
	int firsttime = 1;
	if ((IN = fopen("gcm.in", "rt")) == NULL)
		return 1;
	if ((OUT = fopen("gcm.out", "wt")) == NULL)
	{
		fclose(IN);
		return 1;
	}
	
	fscanf(IN, "%I64d", &a);
	fscanf(IN, "%I64d", &b);

	for (a1 = min(a, b); a1 <= max(a, b); a1++)
	{
		b1 = a * b / a1;
		if (NOD(a, b) == NOD(a1, b1) && NOK(a, b) == NOK(a1, b1))
			if ((my_abs(a1 - b1) < my_abs(mina - minb)) || firsttime)
			{
			mina = a1;
			minb = b1;
			firsttime = 0;
			}
	}

	fprintf(OUT, "%I64d %I64d", mina, minb);
	fclose(IN);
	fclose(OUT);
	return 0;
}
예제 #2
0
int main(void)
{
	FILE *FIn, *FOut;
	int i, j, max, a, b, min, x, y, nod, nok;

	if ((FIn = fopen("gcm.in", "rt")) == NULL)
		return 0;
	if ((FOut = fopen("gcm.out", "wt")) == NULL)
		return 0;
	fscanf(FIn, "%d%d", &a, &b);
	if (a > b)
		max = a, min = a - b;
	else
		max = b, min = b - a;
	nod = NOD(a, b);
	nok = NOK(a, b);
	x = a;
	y = b;
	for (i = 1; i <= max; i++)
	{
		j = (int)(a * b / i);
		if (i > j)
			break;
		if (min > Minus(i, j) && nod == NOD(i, j) && nok == NOK(i, j))
			x = i, y = j;
	}
	fprintf(FOut, "%d %d", x, y);
	fclose(FIn);
	fclose(FOut);
}
int main(){
    int a,b,c;
    
    cout<<"Vvedit' a,b,c:"<<endl;
    cin>>a>>b>>c;
    
    cout<<"NOD("<<a<<","<<b<<","<<c<<")="<<NOD(NOD(a,b),c);
    getch();
    return 0;
}
예제 #4
0
파일: Jet.cpp 프로젝트: dhidas/UserCode
bool Jet::isGood() const {
    // bool passesPt = pt() > 30; // Bristol original value
    bool passesPt = pt() > 35;  // 19.07.11 Chris's value
    bool passesEta = fabs(eta()) < 2.4;
    bool jetID = false;
    //if (usedAlgorithm == JetAlgorithm::ParticleFlow || usedAlgorithm == JetAlgorithm::PF2PAT) {
    if (usedAlgorithm == JetAlgorithm::CA08PF || usedAlgorithm == JetAlgorithm::PF2PAT) {
        bool passNOD = NOD() > 1;
        bool passCEF = CEF() < 0.99;
        bool passNHF = NHF() < 0.99;
        bool passNEF = NEF() < 0.99;
        bool passCHF = true;
        bool passNCH = true;
        if (fabs(eta()) < 2.4) {
            passCHF = CHF() > 0;
            passNCH = NCH() > 0;
        }
        jetID = passNOD && passCEF && passNHF && passNEF && passCHF && passNCH;
    }
    else{
        bool passesEMF = emf() > 0.01;
        bool passesN90Hits = n90Hits() > 1;
        bool passesFHPD = fHPD() < 0.98;
        jetID = passesEMF && passesN90Hits && passesFHPD;
    }
    return passesPt && passesEta && jetID;
}
예제 #5
0
파일: stdafx.cpp 프로젝트: vova98/Isengreem
int NOD(int a, int b)
{
	//int x = 0;
	if (a != 0)
		return NOD(b%a,a);
	else return b;

	return b;
}
예제 #6
0
SWORD NOD(SWORD a, SWORD b)
{
	SWORD i;
	for (i = 2; i <= min(a, b); i++)
	{
		if (((a % i) == 0) && ((b % i) == 0))
			return i * NOD(a / i, b / i);
	}
	return 1;
}
예제 #7
0
int NOD(int m, int n)
{
	if (m == 0)
		return n;
	if (n == 0)
		return m;
	if (m == n)
		return m;

	if (m % 2 == 0 && n % 2 == 0)
		return 2 * NOD(m / 2, n / 2);
	if (m % 2 == 0 && n % 2 == 1)
		return NOD(m / 2, n);
	if (m % 2 == 1 && n % 2 == 0)
		return NOD(m, n / 2);
	if (m % 2 == 1 && n % 2 == 1 && n > m)
		return NOD((n - m) / 2, m);
	if (m % 2 == 1 && n % 2 == 1 && m > n)
		return NOD((m - n) / 2, n);
	return 1;
}
예제 #8
0
파일: fio_icmp.c 프로젝트: a5216652166/ddd
inline int32_t fio_icmp_handle_req(struct fio_nic *nic, struct fio_rxdata *rxd, void *param)
{
    NOD("");
    //fprintf(stderr, "fio_icmp_handle_req\n");
    struct fio_txdata *m;
    struct icmp_packet *ppkt_rx = (struct icmp_packet*)rxd->pbuf;
    if ((uint8_t)ICMP_ECHOREPLY == ppkt_rx->icmp.icmp_type
            || !fio_nic_is_myip(nic, rxd->dip))
    {
        fio_stack_deliver(nic, rxd);
        goto suc;
    }

    uint32_t sip = 0, nip, get_ret = 0;
    int dev_idx;
    if (0 != fio_route_find(nic, ntohl(rxd->sip), &sip, &dev_idx, &nip))
        goto err;

    if (dev_idx != nic->type_id)
    {
        fio_stack_deliver(nic, rxd);
        goto suc;
    }
    if (fio_nic_reserve_tx(nic, &m, rxd) < 1)
        goto err;
    get_ret = fio_mac_get_bynip(nic, nip, &m->dmac, ntohl(rxd->dip));
    struct icmp_packet *ppkt_tx = (struct icmp_packet*)m->pbuf;
    struct ether_header *eh = &ppkt_tx->eh;
    if (fio_icmp_gen_resp(nic, ppkt_rx, ppkt_tx, rxd, m->type))
    {
        OD( "tid %d generate icmp reply packet error", NIC_EXTRA_CONTEXT(nic)->me);
        goto err;
    }
    m->size = rxd->size;
    if (0 == get_ret)
    {
        prmac((uint8_t*)m->dmac);
        bcopy(m->dmac, eh->ether_dhost, ETH_ALEN);
        fio_nic_commit(nic, m, 1);
    }
    else
    {
        OD( "tid %d generate icmp reply no dst mac", NIC_EXTRA_CONTEXT(nic)->me);
        memset(eh->ether_dhost, 0, ETH_ALEN);
        fio_mac_cache_pkt(nic, nip, m);
    }

suc:
    return 0;
err:
    return -1;
}
예제 #9
0
int main(void)
{
	FILE *FIn, *FOut;
	int i, j, max, a, b, min, x, y, nod, nok;

	if ((FIn = fopen("gcm.in", "rt")) == NULL)
		return 0;
	if ((FOut = fopen("gcm.out", "wt")) == NULL)
		return 0;
	fscanf(FIn, "%d%d", &a, &b);
	if (a > b)
		max = a, min = a - b;
	else
		max = b, min = b - a;
	nod = NOD(a, b);
	nok = NOK(a, b);
	for (i = 1; i <= max; i++)
		for (j = 1; j <= max; j++)
			if (nod == NOD(i, j) && nok == NOK(i, j) && min > Minus(i, j))
				x = j, y = i;
	fprintf(FOut, "%d %d", x, y);
	fclose(FIn);
	fclose(FOut);
}
예제 #10
0
파일: fio.c 프로젝트: a5216652166/ddd
int handle_udps(struct fio_nic *from, struct fio_nic *nic0, struct fio_nic *nic1, 
        struct fio_rxdata *rxdata, int avail, void *useless)
{
    (void)useless;
    struct fio_txdata *txdata;
    int txcount, i;
    //uint32_t sip;
    //uint16_t sport, recvport;

    struct fio_nic *to = nic0;
    if (NIC_EXTRA_TYPEID(from) == NIC_EXTRA_TYPEID(nic0))
        to = nic1;

    for (i = 0; i < avail; i++, rxdata++)
    {
        txcount = fio_nic_reserve_tx(to, &txdata, rxdata);
        if (nm_unlikely(txcount != 1))
        {
            OD("tid %d reserve realtime tx error", NIC_EXTRA_CONTEXT(to)->me);
        }
        //sport = ntohs(rxdata->sport);
		//if (sport == 9998)
		//	assert(0);
        //recvport = ntohs(rxdata->dport);
        //char str_sip[16];
        NOD("tid %d: dsize %d sip %s sport %d recvport %d", 
                NIC_EXTRA_CONTEXT(to)->me, rxdata->size, inet_ntop(AF_INET,
                    (struct in_addr*)&rxdata->sip, str_sip, 16), sport, recvport); 

        txdata->dstip = sysconfig.dst_ip[0].start.s_addr;
        txdata->dstport = htons(sysconfig.dst_port);
        txdata->srcip = 0;
        txdata->srcport = htons(sysconfig.src_port);
        fio_send(to, htons(fio_set_txmsg(to, txdata)), txdata, 0);
        //fio_nic_sendmsg_direct(to, sysconfig.dst_ip.start.s_addr, txdata);
    }

    return 0;
}
예제 #11
0
파일: fio.c 프로젝트: a5216652166/ddd
int handle_udps_2cards(struct fio_nic *from, struct fio_nic *nic0, struct fio_nic *nic1, 
        struct fio_rxdata *rxdata, int avail, void *useless)
{
    (void)useless;
    struct fio_txdata *txdata;
    int txcount, i;
    //uint32_t sip;
    //uint16_t sport, recvport;

    uint32_t dstip = 0;

    if (NIC_EXTRA_CONTEXT(from)->nics[0].fd == from->fd)
       dstip = sysconfig.dst_ip[0].start.s_addr;
    else
       dstip = sysconfig.dst_ip[1].start.s_addr;

    for (i = 0; i < avail; i++, rxdata++)
    {
        txcount = fio_nic_reserve_tx(from, &txdata, rxdata);
        if (nm_unlikely(txcount != 1))
        {
            OD("tid %d reserve realtime tx error", NIC_EXTRA_CONTEXT(from)->me);
        }
        //sport = ntohs(rxdata->sport);
        //recvport = ntohs(rxdata->dport);
        //char str_sip[16];
        NOD("tid %d: dsize %d sip %s sport %d recvport %d", 
                NIC_EXTRA_CONTEXT(from)->me, rxdata->size, inet_ntop(AF_INET,
                    (struct in_addr*)&rxdata->sip, str_sip, 16), sport, recvport); 

        txdata->dstip = dstip;
        txdata->dstport = htons(sysconfig.dst_port);
        txdata->srcip = 0;
        txdata->srcport = htons(sysconfig.src_port);
        fio_send(from, htons(fio_set_txmsg(from, txdata)), txdata, 0);
    }

    return 0;
}
예제 #12
0
파일: fio.c 프로젝트: a5216652166/ddd
int handle_audp(struct fio_nic *from, struct fio_nic *to, struct fio_rxdata *rxdata, 
        uint32_t sip, uint16_t sport, uint16_t recvport, void *useless)
{
    struct fio_txdata *txdata;
    int txcount;
    sport = ntohs(sport);
    recvport = ntohs(recvport);
    //char str_sip[16];
    NOD("tid %d: dsize %d sip %s sport %d recvport %d", 
            NIC_EXTRA_CONTEXT(from)->me, rxdata->size, inet_ntop(AF_INET,
                (struct in_addr*)&sip, str_sip, 16), sport, recvport); 

    txcount = fio_nic_reserve_tx(to, &txdata, rxdata);
    if (txcount == 1)
    {
        fio_nic_sendmsg_direct(to, sysconfig.dst_ip[0].start.s_addr, txdata);
        fio_stack_send_up(to, txdata->pbuf, txdata->size);
    }
    else
    {
        OD("tid %d reserve realtime tx error", NIC_EXTRA_CONTEXT(from)->me);
        exit(1);
    }

    //txcount = fio_reserve_tx(t, 1, &txdata, NULL, 1);
    //if (txcount == 1)
    //{
    //    fio_sendmsg(t, sysconfig.dst_ip.start.s_addr, htons(sysconfig.dst_port), 
    //            htons(sysconfig.src_port), htons(fio_set_txmsg(t, txdata)), txdata);
    //}
    //else
    //{
    //    D("tid %d reserve tx error", t->me);
    //    exit(1);
    //}

    return 0;
}
int NOD(int a, int b){
  if(b==0) return a;
  else return NOD(b, a%b);    
}
예제 #14
0
int NOK(int a, int b)
{
	return (int)a / NOD(a, b) * b;
}
예제 #15
0
//
//  Specialize_Action_Throws: C
//
// Create a new ACTION! value that uses the same implementation as another,
// but just takes fewer arguments or refinements.  It does this by storing a
// heap-based "exemplar" FRAME! in the specialized action; this stores the
// values to preload in the stack frame cells when it is invoked.
//
// The caller may provide information on the order in which refinements are
// to be specialized, using the data stack.  These refinements should be
// pushed in the *reverse* order of their invocation, so append/dup/part
// has /DUP at DS_TOP, and /PART under it.  List stops at lowest_ordered_dsp.
//
bool Specialize_Action_Throws(
    REBVAL *out,
    REBVAL *specializee,
    REBSTR *opt_specializee_name,
    REBVAL *opt_def, // !!! REVIEW: binding modified directly (not copied)
    REBDSP lowest_ordered_dsp
){
    assert(out != specializee);

    struct Reb_Binder binder;
    if (opt_def)
        INIT_BINDER(&binder);

    REBACT *unspecialized = VAL_ACTION(specializee);

    // This produces a context where partially specialized refinement slots
    // will be on the stack (including any we are adding "virtually", from
    // the current DSP down to the lowest_ordered_dsp).
    //
    REBCTX *exemplar = Make_Context_For_Action_Push_Partials(
        specializee,
        lowest_ordered_dsp,
        opt_def ? &binder : nullptr,
        CELL_MASK_NON_STACK
    );
    Manage_Array(CTX_VARLIST(exemplar)); // destined to be managed, guarded

    if (opt_def) { // code that fills the frame...fully or partially
        //
        // Bind all the SET-WORD! in the body that match params in the frame
        // into the frame.  This means `value: value` can very likely have
        // `value:` bound for assignments into the frame while `value` refers
        // to whatever value was in the context the specialization is running
        // in, but this is likely the more useful behavior.
        //
        // !!! This binds the actual arg data, not a copy of it--following
        // OBJECT!'s lead.  However, ordinary functions make a copy of the
        // body they are passed before rebinding.  Rethink.

        // See Bind_Values_Core() for explanations of how the binding works.

        Bind_Values_Inner_Loop(
            &binder,
            VAL_ARRAY_AT(opt_def),
            exemplar,
            FLAGIT_KIND(REB_SET_WORD), // types to bind (just set-word!)
            0, // types to "add midstream" to binding as we go (nothing)
            BIND_DEEP
        );

        // !!! Only one binder can be in effect, and we're calling arbitrary
        // code.  Must clean up now vs. in loop we do at the end.  :-(
        //
        RELVAL *key = CTX_KEYS_HEAD(exemplar);
        REBVAL *var = CTX_VARS_HEAD(exemplar);
        for (; NOT_END(key); ++key, ++var) {
            if (Is_Param_Unbindable(key))
                continue; // !!! is this flag still relevant?
            if (Is_Param_Hidden(key)) {
                assert(GET_CELL_FLAG(var, ARG_MARKED_CHECKED));
                continue;
            }
            if (GET_CELL_FLAG(var, ARG_MARKED_CHECKED))
                continue; // may be refinement from stack, now specialized out
            Remove_Binder_Index(&binder, VAL_KEY_CANON(key));
        }
        SHUTDOWN_BINDER(&binder);

        // Run block and ignore result (unless it is thrown)
        //
        PUSH_GC_GUARD(exemplar);
        bool threw = Do_Any_Array_At_Throws(out, opt_def, SPECIFIED);
        DROP_GC_GUARD(exemplar);

        if (threw) {
            DS_DROP_TO(lowest_ordered_dsp);
            return true;
        }
    }

    REBVAL *rootkey = CTX_ROOTKEY(exemplar);

    // Build up the paramlist for the specialized function on the stack.
    // The same walk used for that is used to link and process REB_X_PARTIAL
    // arguments for whether they become fully specialized or not.

    REBDSP dsp_paramlist = DSP;
    Move_Value(DS_PUSH(), ACT_ARCHETYPE(unspecialized));

    REBVAL *param = rootkey + 1;
    REBVAL *arg = CTX_VARS_HEAD(exemplar);

    REBDSP ordered_dsp = lowest_ordered_dsp;

    for (; NOT_END(param); ++param, ++arg) {
        if (TYPE_CHECK(param, REB_TS_REFINEMENT)) {
            if (IS_NULLED(arg)) {
                //
                // A refinement that is nulled is a candidate for usage at the
                // callsite.  Hence it must be pre-empted by our ordered
                // overrides.  -but- the overrides only apply if their slot
                // wasn't filled by the user code.  Yet these values we are
                // putting in disrupt that detection (!), so use another
                // flag (PUSH_PARTIAL) to reflect this state.
                //
                while (ordered_dsp != dsp_paramlist) {
                    ++ordered_dsp;
                    REBVAL *ordered = DS_AT(ordered_dsp);

                    if (not IS_WORD_BOUND(ordered))  // specialize 'print/asdf
                        fail (Error_Bad_Refine_Raw(ordered));

                    REBVAL *slot = CTX_VAR(exemplar, VAL_WORD_INDEX(ordered));
                    if (
                        IS_NULLED(slot) or GET_CELL_FLAG(slot, PUSH_PARTIAL)
                    ){
                        // It's still partial, so set up the pre-empt.
                        //
                        Init_Any_Word_Bound(
                            arg,
                            REB_SYM_WORD,
                            VAL_STORED_CANON(ordered),
                            exemplar,
                            VAL_WORD_INDEX(ordered)
                        );
                        SET_CELL_FLAG(arg, PUSH_PARTIAL);
                        goto unspecialized_arg;
                    }
                    // Otherwise the user filled it in, so skip to next...
                }

                goto unspecialized_arg;  // ran out...no pre-empt needed
            }

            if (GET_CELL_FLAG(arg, ARG_MARKED_CHECKED)) {
                assert(
                    IS_BLANK(arg)
                    or (
                        IS_REFINEMENT(arg)
                        and (
                            VAL_REFINEMENT_SPELLING(arg)
                            == VAL_PARAM_SPELLING(param)
                        )
                    )
                );
            }
            else
                Typecheck_Refinement_And_Canonize(param, arg);

            goto specialized_arg_no_typecheck;
        }

        switch (VAL_PARAM_CLASS(param)) {
          case REB_P_RETURN:
          case REB_P_LOCAL:
            assert(IS_NULLED(arg)); // no bindings, you can't set these
            goto unspecialized_arg;

          default:
            break;
        }

        // It's an argument, either a normal one or a refinement arg.

        if (not IS_NULLED(arg))
            goto specialized_arg_with_check;

    unspecialized_arg:

        assert(NOT_CELL_FLAG(arg, ARG_MARKED_CHECKED));
        assert(
            IS_NULLED(arg)
            or (IS_SYM_WORD(arg) and TYPE_CHECK(param, REB_TS_REFINEMENT))
        );
        Move_Value(DS_PUSH(), param);
        continue;

    specialized_arg_with_check:

        // !!! If argument was previously specialized, should have been type
        // checked already... don't type check again (?)
        //
        if (Is_Param_Variadic(param))
            fail ("Cannot currently SPECIALIZE variadic arguments.");

        if (TYPE_CHECK(param, REB_TS_DEQUOTE_REQUOTE) and IS_QUOTED(arg)) {
            //
            // Have to leave the quotes on, but still want to type check.

            if (not TYPE_CHECK(param, CELL_KIND(VAL_UNESCAPED(arg))))
                fail (arg); // !!! merge w/Error_Invalid_Arg()
        }
        else if (not TYPE_CHECK(param, VAL_TYPE(arg)))
            fail (arg); // !!! merge w/Error_Invalid_Arg()

       SET_CELL_FLAG(arg, ARG_MARKED_CHECKED);

    specialized_arg_no_typecheck:

        // Specialized-out arguments must still be in the parameter list,
        // for enumeration in the evaluator to line up with the frame values
        // of the underlying function.

        assert(GET_CELL_FLAG(arg, ARG_MARKED_CHECKED));
        Move_Value(DS_PUSH(), param);
        TYPE_SET(DS_TOP, REB_TS_HIDDEN);
        continue;
    }

    REBARR *paramlist = Pop_Stack_Values_Core(
        dsp_paramlist,
        SERIES_MASK_PARAMLIST
            | (SER(unspecialized)->header.bits & PARAMLIST_MASK_INHERIT)
    );
    Manage_Array(paramlist);
    RELVAL *rootparam = ARR_HEAD(paramlist);
    VAL_ACT_PARAMLIST_NODE(rootparam) = NOD(paramlist);

    // Everything should have balanced out for a valid specialization
    //
    while (ordered_dsp != DSP) {
        ++ordered_dsp;
        REBVAL *ordered = DS_AT(ordered_dsp);
        if (not IS_WORD_BOUND(ordered))  // specialize 'print/asdf
            fail (Error_Bad_Refine_Raw(ordered));

        REBVAL *slot = CTX_VAR(exemplar, VAL_WORD_INDEX(ordered));
        assert(not IS_NULLED(slot) and NOT_CELL_FLAG(slot, PUSH_PARTIAL));
        UNUSED(slot);
    }
    DS_DROP_TO(lowest_ordered_dsp);

    // See %sysobj.r for `specialized-meta:` object template

    REBVAL *example = Get_System(SYS_STANDARD, STD_SPECIALIZED_META);

    REBCTX *meta = Copy_Context_Shallow_Managed(VAL_CONTEXT(example));

    Init_Nulled(CTX_VAR(meta, STD_SPECIALIZED_META_DESCRIPTION)); // default
    Move_Value(
        CTX_VAR(meta, STD_SPECIALIZED_META_SPECIALIZEE),
        specializee
    );
    if (not opt_specializee_name)
        Init_Nulled(CTX_VAR(meta, STD_SPECIALIZED_META_SPECIALIZEE_NAME));
    else
        Init_Word(
            CTX_VAR(meta, STD_SPECIALIZED_META_SPECIALIZEE_NAME),
            opt_specializee_name
        );

    MISC_META_NODE(paramlist) = NOD(meta);

    REBACT *specialized = Make_Action(
        paramlist,
        &Specializer_Dispatcher,
        ACT_UNDERLYING(unspecialized), // same underlying action as this
        exemplar, // also provide a context of specialization values
        1 // details array capacity
    );
    assert(CTX_KEYLIST(exemplar) == ACT_PARAMLIST(unspecialized));

    assert(
        GET_ACTION_FLAG(specialized, IS_INVISIBLE)
        == GET_ACTION_FLAG(unspecialized, IS_INVISIBLE)
    );

    // The "body" is the FRAME! value of the specialization.  It takes on the
    // binding we want to use (which we can't put in the exemplar archetype,
    // that binding has to be UNBOUND).  It also remembers the original
    // action in the phase, so Specializer_Dispatcher() knows what to call.
    //
    RELVAL *body = ARR_HEAD(ACT_DETAILS(specialized));
    Move_Value(body, CTX_ARCHETYPE(exemplar));
    INIT_BINDING(body, VAL_BINDING(specializee));
    INIT_VAL_CONTEXT_PHASE(body, unspecialized);

    Init_Action_Unbound(out, specialized);
    return false; // code block did not throw
}
예제 #16
0
Rational::Rational(int a, int b) 
{
    num = a / NOD(a,b);
    denom = b / NOD(a,b);
}
예제 #17
0
SWORD NOK(SWORD a, SWORD b)
{
	return a * b / NOD(a,b);
}
예제 #18
0
void Fraction::CutFraction() {
    int nod = NOD();
    numenator = numenator / nod;
    denominator = denominator / nod;
}