QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#586491#5062. SquarehcywoiWA 5ms7000kbC++233.6kb2024-09-24 13:30:452024-09-24 13:30:46

Judging History

你现在查看的是最新测评结果

  • [2024-09-24 13:30:46]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:7000kb
  • [2024-09-24 13:30:45]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

template<class T>
T qmi(T a, i64 b) {
    T res = 1;
    for (; b; b /= 2, a *= a) {
        if (b % 2) {
            res *= a;
        }
    }
    return res;
}

i64 mul(i64 a, i64 b, i64 p) {
    i64 res = a * b - i64(1.L * a * b / p) * p;
    res %= p;
    if (res < 0) {
        res += p;
    }
    return res;
}

template<int P>
struct modint {
    int x;
    constexpr modint() : x{} {}
    constexpr modint(i64 x) : x{norm(x % getmod())} {}

    static int mod;
    constexpr static int getmod() {
        if (P > 0) {
            return P;
        } else {
            return mod;
        }
    }
    constexpr static void setmod(int m) {
        mod = m;
    }
    constexpr int norm(int x) const {
        if (x < 0) {
            x += getmod();
        }
        if (x >= getmod()) {
            x -= getmod();
        }
        return x;
    }
    constexpr int val() const {
        return x;
    }
    explicit constexpr operator int() const {
        return x;
    }
    constexpr modint operator-() const {
        modint res;
        res.x = norm(getmod() - x);
        return res;
    }
    constexpr modint inv() const {
        assert(x != 0);
        return qmi(*this, getmod() - 2);
    }
    constexpr modint &operator*= (modint v) & {
        x = 1LL * x * v.x % getmod();
        return *this;
    }
    constexpr modint &operator+= (modint v) & {
        x = norm(x + v.x);
        return *this;
    }
    constexpr modint &operator-= (modint v) & {
        x = norm(x - v.x);
        return *this;
    }
    constexpr modint &operator/= (modint v) & {
        return *this *= v.inv();
    }
    friend constexpr modint operator- (modint a, modint b) {
        modint res = a;
        res -= b;
        return res;
    }
    friend constexpr modint operator+ (modint a, modint b) {
        modint res = a;
        res += b;
        return res;
    }
    friend constexpr modint operator* (modint a, modint b) {
        modint res = a;
        res *= b;
        return res;
    }
    friend constexpr modint operator/ (modint a, modint b) {
        modint res = a;
        res /= b;
        return res;
    }
    friend constexpr std::istream &operator>> (std::istream& is, modint& a) {
        i64 v;
        is >> v;
        a = modint(v);
        return is;
    }
    friend constexpr std::ostream &operator<< (std::ostream& os, const modint& a) {
        return os << a.val();
    }
    friend constexpr bool operator== (modint a, modint b) {
        return a.val() == b.val();
    }
    friend constexpr bool operator!= (modint a, modint b) {
        return a.val() != b.val();
    }
};

constexpr int P = 1000000007;
using mint = modint<P>;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    constexpr int V = 1E6 + 5;
    std::vector<int> fac(V);
    for (int i = 0; i < n; i ++ ) {
        int a;
        std::cin >> a;
        for (int j = 2; j <= a / j; j ++ ) {
            if (a % j == 0) {
                int c = 0;
                while (a % j == 0) {
                    a /= j;
                    c ++ ;
                }
                fac[j] += c % 2;
            }
        }
        if (a > 1) {
            fac[a] += 1;
        }
    }

    mint ans = 1;
    for (int i = 1; i < V; i ++ ) {
        int t = std::min(fac[i], n - fac[i]);
        if (t > 0) {
            ans *= i * t;
        }
    }

    std::cout << ans << "\n";

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 7000kb

input:

3
2 3 6

output:

6

result:

ok 1 number(s): "6"

Test #2:

score: 0
Accepted
time: 2ms
memory: 7000kb

input:

1
1

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 5ms
memory: 6992kb

input:

100000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 2ms
memory: 6936kb

input:

1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 2ms
memory: 6916kb

input:

1
130321

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 2ms
memory: 6900kb

input:

1
85849

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: -100
Wrong Answer
time: 0ms
memory: 6900kb

input:

10
1 37249 1 193 1 193 193 193 1 37249

output:

772

result:

wrong answer 1st numbers differ - expected: '387487994', found: '772'