Logo Wy Online Judge

WyOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#502#4. 「WyOJ Round 1」启 · 破茧初阳Pigsyy10028896ms3476kbC++238.3kb2025-04-25 18:16:052025-04-25 18:16:05

answer

#include<bits/stdc++.h>
using namespace std;

struct _int128 {
    unsigned long long low;
    long long high;
    bool sign;
    _int128(): low(0), high(0), sign(1) {}
    _int128(unsigned long long a, long long b, bool c = 1):
        low(a), high(b), sign(c) {}
    _int128(char a): low(abs(a)), high(0), sign(a >= 0) {}
    _int128(unsigned char a): low(a), high(0), sign(1) {}
    _int128(short a): low(abs(a)), high(0), sign(a >= 0) {}
    _int128(unsigned short a): low(a), high(0), sign(1) {}
    _int128(int a): low(abs(a)), high(0), sign(a >= 0) {}
    _int128(unsigned int a): low(a), high(0), sign(1) {}
    _int128(long long a): low(abs(a)), high(0), sign(a >= 0) {}
    _int128(unsigned long long a): low(a), high(0), sign(1) {}
    explicit operator char() {
        return (char)low;
    }
    explicit operator unsigned char() {
        unsigned char res = low;

        if (!sign)
            res = -res;

        return res;
    }
    explicit operator short() {
        return (short)low;
    }
    explicit operator unsigned short() {
        unsigned short res = low;

        if (!sign)
            res = -res;

        return res;
    }
    explicit operator int() {
        return (int)low;
    }
    explicit operator unsigned int() {
        unsigned int res = low;

        if (!sign)
            res = -res;

        return res;
    }
    explicit operator long long() {
        return (long long)low;
    }
    explicit operator unsigned long long() {
        unsigned long long res = low;

        if (!sign)
            res = -res;

        return res;
    }

    _int128 operator= (const _int128 &x) {
        low = x.low, high = x.high, sign = x.sign;
        return (*this);
    }
    bool operator!() const {
        return low == 0 && high == 0;
    }
    bool operator== (const _int128 &y) const {
        auto x = (*this);
        return x.sign == y.sign && x.low == y.low && x.high == y.high;
    }
    bool operator< (const _int128 &y) const {
        auto x = (*this);

        if (x.sign < y.sign)
            return 1;

        if (x.sign > y.sign)
            return 0;

        if (x.high < y.high)
            return 1;

        if (x.high > y.high)
            return 0;

        if (x.low < y.low)
            return 1;

        if (x.low > y.low)
            return 0;

        return 0;
    }
    bool operator<= (const _int128 &y) const {
        auto x = (*this);
        return x < y || x == y;
    }
    bool operator> (const _int128 &y) const {
        auto x = (*this);
        return !(x <= y);
    }
    bool operator>= (const _int128 &y) const {
        auto x = (*this);
        return !(x < y);
    }
    _int128 operator- () {
        auto t = (*this);
        t.sign ^= 1;
        return t;
    }
    _int128 add(_int128 x, _int128 y) {
        auto lo = x.low + y.low;
        auto hi = x.high + y.high;
        hi += lo < x.low;
        return _int128(lo, hi);
    }
    _int128 sub(_int128 x, _int128 y) {
        bool neg = false;

        if (x < y)
            swap(x, y), neg = true;

        auto lo = x.low - y.low;
        auto hi = x.high - y.high;
        hi -= x.low < y.low;
        return _int128(lo, hi, !neg);
    }
    _int128 operator+ (_int128 y) {
        auto x = (*this);

        if (x.sign ^ y.sign) {
            if (x < y)
                swap(x, y);

            return sub(x, y);
        } else {
            auto t = add(x, y);
            t.sign ^= !x.sign;
            return t;
        }
    }
    _int128 operator+= (const _int128 &x) {
        return (*this) = (*this) + x;
    }
    _int128 operator- (_int128 y) const {
        auto x = (*this);
        return x + (-y);
    }
    _int128 operator-= (const _int128 &x) {
        return (*this) = (*this) - x;
    }
    _int128 operator<< (const unsigned long long &y) const {
        auto x = (*this);

        if (y > 128)
            return _int128(0, 0);

        if (y >= 64) {
            return _int128(0, x.low << (y - 64), x.sign);
        } else {
            _int128 res = x;
            unsigned long long t = x.low >> (64 - y);
            res.high = (res.high << y) + t;
            res.low = res.low << y;
            return res;
        }
    }
    _int128 operator<<= (const unsigned long long &y) {
        return (*this) = (*this) << y;
    }
    _int128 operator>> (const unsigned long long &y) const {
        auto x = (*this);

        if (y > 128)
            return _int128(0, 0);

        if (y >= 64) {
            return _int128(x.high >> (y - 64), 0, x.sign);
        } else {
            _int128 res = x;
            unsigned long long t = x.high & ((1ll << y) - 1);
            res.low = (res.low >> y) + (t << (64 - y));
            res.high = res.high >> y;
            return res;
        }
    }
    _int128 operator>>= (const unsigned long long &y) {
        return (*this) = (*this) >> y;
    }
    _int128 operator& (_int128 y) {
        auto x = (*this);

        if (!x.sign)
            x.low = ~x.low, x.high = ~x.high;

        if (!y.sign)
            y.low = ~y.low, y.high = ~y.high;

        return _int128(x.low & y.low, abs(x.high & y.high), x.sign | y.sign);
    }
    _int128 operator| (_int128 y) {
        auto x = (*this);

        if (!x.sign)
            x.low = ~x.low, x.high = ~x.high;

        if (!y.sign)
            y.low = ~y.low, y.high = ~y.high;

        return _int128(x.low | y.low, abs(x.high | y.high), x.sign & y.sign);
    }
    _int128 operator^ (_int128 y) {
        auto x = (*this);

        if (!x.sign)
            x.low = ~x.low, x.high = ~x.high;

        if (!y.sign)
            y.low = ~y.low, y.high = ~y.high;

        return _int128(x.low ^ y.low, abs(x.high ^ y.high), !(x.sign ^ y.sign));
    }
    _int128 operator&= (const _int128 &x) {
        return (*this) = (*this) & x;
    }
    _int128 operator|= (const _int128 &x) {
        return (*this) = (*this) | x;
    }
    _int128 operator^= (const _int128 &x) {
        return (*this) = (*this) ^ x;
    }
    _int128 operator* (const _int128 &y) const {
        auto x = (*this);
        long long H = x.high * y.low + x.low * y.high, L = 0;
        unsigned int LH1 = x.low / (1ll << 32), LH2 = y.low / (1ll << 32);
        unsigned int LL1 = x.low, LL2 = y.low;
        H += (long long)LH1 * LH2, L += (unsigned long long)LL1 * LL2;
        _int128 res = _int128(L, H, !(x.sign xor y.sign));
        res += _int128((unsigned long long)LL1 * LH2) << 32;
        res += _int128((unsigned long long)LH1 * LL2) << 32;
        return res;
    }
    _int128 operator*= (const _int128 &y) {
        return (*this) = (*this) * y;
    }
    _int128 operator/ (_int128 y) const {
        auto x = (*this), z = _int128(1);

        while (y <= x)
            y <<= 1, z <<= 1;

        _int128 res = 0;

        while (y > 0) {
            if (x >= y) {
                x -= y;
                res |= z;
            }

            y >>= 1, z >>= 1;
        }

        res.sign = !(x.sign ^ y.sign);
        return res;
    }
    _int128 operator/= (const _int128 &y) {
        return (*this) = (*this) / y;
    }
    _int128 operator% (const _int128 &y) const {
        auto x = (*this);
        return x - x / y * y;
    }
};
typedef long long ll;
typedef _int128 LLL;
const ll N=3e3+50;
LLL n,a,b,c,m;

LLL read() {
    LLL x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}


void out(LLL x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) out(x / 10);
    putchar((int)(x % 10 + '0'));
}

LLL gcd(LLL x,LLL y){
    return (y==0?x:gcd(y,x%y));
}

LLL lcm(LLL x,LLL y){
    return x/gcd(x,y)*y;
}

int main(){
    n=read();
    
    for(LLL i=1;i<=n;i+=1){
//      scanf("%lld%lld%lld%lld",&m,&a,&b,&c);
        m=read(),a=read(),b=read(),c=read();
        out(m/a-m/lcm(a,b)+m/c-m/lcm(a,c)+m/lcm(lcm(a,b),c));
        printf("\n");
//      printf("%lld\n",m/a-m/lcm(a,b)+m/c-m/lcm(a,c)+m/lcm(lcm(a,b),c));
    }
    
    return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 3ms
memory: 3128kb

input:

5
860162 209867 500351 439559
603171 218577 395789 743662
257237 83 83 97
771353 21 25 28
882442 63 ...

output:

5
2
2651
53995
38632

result:

ok 5 number(s): "5 2 2651 53995 38632"

Test #2:

score: 10
Accepted
time: 3ms
memory: 3284kb

input:

5
65586 755707 428352 829618
656029 940749 988704 99212
36268 81 74 19
30582 39 65 84
169669 10 30 86

output:

0
6
2326
969
13020

result:

ok 5 number(s): "0 6 2326 969 13020"

Test #3:

score: 10
Accepted
time: 3ms
memory: 3124kb

input:

5
1000000 823597 291727 302588
1000000 110582 88125 289933
1000000 56 41 6
1000000 97 68 23
1000000 ...

output:

4
12
178281
53194
27737

result:

ok 5 number(s): "4 12 178281 53194 27737"

Test #4:

score: 10
Accepted
time: 2ms
memory: 3280kb

input:

5
1000000 391577 925090 509576
1000000 602666 793626 529237
1000000 34 9 9
1000000 34 31 68
1000000 ...

output:

3
2
137255
28937
35714

result:

ok 5 number(s): "3 2 137255 28937 35714"

Test #5:

score: 10
Accepted
time: 4700ms
memory: 3476kb

input:

100000
296432115736998358 947322129 486697382 491023976
442633183062920521 378805523 642688939 22691...

output:

916617773
3119191450
2944253854
238707775
758558510
1988904951
2242369622
83414679
2053708470
530923...

result:

ok 100000 numbers

Test #6:

score: 10
Accepted
time: 4688ms
memory: 3204kb

input:

100000
673374200126361826 331800367 162665250 387080263
144151428834647945 126886572 51580646 287850...

output:

3769080063
1636851827
264014313
1850411469
1298622147
8929671
145894145
3638772267
1366556156
158219...

result:

ok 100000 numbers

Test #7:

score: 10
Accepted
time: 4687ms
memory: 3132kb

input:

100000
534714905018631481 79508556 404238398 161736622
3826684598814001 497377457 854258623 48373266...

output:

10031334031
86801149
1002404788
10758368311
272870805
1301299250
4023999178
43559655
487933681
20645...

result:

ok 100000 numbers

Test #8:

score: 10
Accepted
time: 4945ms
memory: 3248kb

input:

100000
1000000000000000000 366727583 374716263 685187467
1000000000000000000 877263942 598947447 372...

output:

4186274294
3823951000
12291730057
11258373300
3930377537
2876479471
2879685285
4909612902
8010498639...

result:

ok 100000 numbers

Test #9:

score: 10
Accepted
time: 4936ms
memory: 3416kb

input:

100000
1000000000000000000 979092025 33346302 238829786
1000000000000000000 460728333 175754163 3332...

output:

5208436845
32181643966
9585743799
6068098504
7167226129
5961403001
3843724974
5685808316
4804644411
...

result:

ok 100000 numbers

Test #10:

score: 10
Accepted
time: 4929ms
memory: 3284kb

input:

100000
1000000000000000000 437307257 195856865 910658369
1000000000000000000 384087547 596914446 797...

output:

3384828338
15135841918
3977256414
7592860744
5137818933
17475999767
29047755731
4258627888
968000942...

result:

ok 100000 numbers

Extra Test:

score: 0
Extra Test Passed