4 条题解

  • 0
    @ 2026-05-31 21:11:38

    奇怪的卡常题

    #include <cstdio>
    #include <cstdint>
    #include <algorithm>
    using namespace std;
    
    // 快速二进制 gcd,避免除法与取模
    int fast_gcd(int a, int b) {
        if (a == 0) return b;
        if (b == 0) return a;
        int az = __builtin_ctz(a);
        int bz = __builtin_ctz(b);
        int shift = az < bz ? az : bz;
        a >>= az;
        b >>= bz;
        while (a != b) {
            if (a > b) {
                a -= b;
                a >>= __builtin_ctz(a);
            } else {
                b -= a;
                b >>= __builtin_ctz(b);
            }
        }
        return a << shift;
    }
    
    int a[2000], b[2000];
    
    int main() {
        int n, m;
        scanf("%d%d", &n, &m);
        for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
        for (int i = 0; i < m; ++i) scanf("%d", &b[i]);
    
        uint32_t ans = 0;
        for (int i = 0; i < n; ++i) {
            int ai = a[i];
            uint32_t ixor = (uint32_t)i;   // 提前转换,避免内层重复转换
            for (int j = 0; j < m; ++j) {
                int bj = b[j];
                int g;
                if (ai == 0) g = bj;
                else if (bj == 0) g = ai;
                else g = fast_gcd(ai, bj);
                ans += g ^ ixor ^ (uint32_t)j;
            }
        }
        printf("%u\n", ans);
        return 0;
    }
    
  • -7
    @ 2021-05-29 10:28:24

    ...

  • -12
    @ 2018-02-12 18:34:23

    、、

  • -13
    #include <stdio.h>
    __attribute__((optimize("-O3"))) main(){for (;;) puts("傻逼");}
    
    • @ 2021-07-21 20:53:32

      你妈¥了

    • @ 2022-01-13 18:14:27

      去你妈的,your mother Boom!!!!!

    • @ 2022-05-22 09:40:40

      去你妈的,your mother Boom!!!!!

    • @ 2022-05-22 09:40:53

      去你妈的,your mother SL!!!!!

  • 1

信息

ID
1992
难度
8
分类
(无)
标签
(无)
递交数
53
已通过
8
通过率
15%
被复制
2
上传者