QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#609687#9248. An Easy Math Problemucup-team1001#TL 8ms7708kbC++231.8kb2024-10-04 13:43:412024-10-04 13:43:53

Judging History

This is the latest submission verdict.

  • [2024-10-31 22:36:43]
  • hack成功,自动添加数据
  • (/hack/1098)
  • [2024-10-31 22:13:58]
  • hack成功,自动添加数据
  • (/hack/1096)
  • [2024-10-31 22:00:43]
  • hack成功,自动添加数据
  • (/hack/1095)
  • [2024-10-04 13:43:53]
  • Judged
  • Verdict: TL
  • Time: 8ms
  • Memory: 7708kb
  • [2024-10-04 13:43:41]
  • Submitted

answer

#include "bits/stdc++.h"

using i64 = long long;
using namespace std;

vector<int> pp;

vector<int> getprime(int n) {
    vector<int> p;
    vector<int> pri(n + 1);
    for (int i = 2; i <= n; i++) {
        if (pri[i]) continue;
        p.emplace_back(i);
        for (int j = i; j <= n; j += i) {
            pri[j] = 1;
        }
    }
    return p;
}

i64 qpow(i64 a, i64 b) {
    i64 res = 1;
    while (b) {
        if (b & 1) res *= a;
        a = a * b;
        b /= 2;
    }
}

void solve() {
    i64 n;
    int res = 1;

    vector<pair<i64, i64>> mp;
    cin >> n;
    if (n == 1) {
        cout << 1 << endl;
        return;
    }
    for (auto i: pp) {
        if (n % i == 0) {
            int t = 0;
            while (n % i == 0) {
                t++;
                n /= i;
            }
            mp.emplace_back(i, t);
        }
        if (i * i > n) {
            if (n != 1)
                mp.emplace_back(n, 1);
            break;
        }
    }
    set<pair<int, int>> s;
    function<void(int, i64, i64)> dfs = [&](int n, i64 a, i64 b) {
//        cerr << a << " " << b << endl;
        if (a < b) {
            if (!s.count({a, b})) {
                s.emplace(a, b);
                res++;
            }
        }
        if (n == mp.size()) {
            return;
        }
        dfs(n + 1, a, b);
        auto [k, t] = mp[n];
        i64 zz = 1;
        for (int i = 1; i <= t; i++) {
            zz *= k;
            dfs(n + 1, a * zz, b);
            dfs(n + 1, a, b * zz);
        }
    };
    dfs(0, 1, 1);
    cout << res << "\n";


}

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int t;
    pp = getprime(1e6);
    cin >> t;
    while (t--) {
        solve();
    }

}

詳細信息

Test #1:

score: 100
Accepted
time: 8ms
memory: 7708kb

input:

10
1
2
3
4
5
6
7
8
9
10

output:

1
2
2
3
2
5
2
4
3
5

result:

ok 10 lines

Test #2:

score: -100
Time Limit Exceeded

input:

2000
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
6469693230
646969323...

output:


result: