QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#670979#9248. An Easy Math ProblemMagiciannnAC ✓83ms3864kbC++203.4kb2024-10-24 09:35:262024-10-31 22:19:33

Judging History

你现在查看的是测评时间为 2024-10-31 22:19:33 的历史记录

  • [2024-10-31 22:42:31]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:AC
  • 用时:83ms
  • 内存:3792kb
  • [2024-10-31 22:36:43]
  • hack成功,自动添加数据
  • (/hack/1098)
  • [2024-10-31 22:19:33]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:83ms
  • 内存:3864kb
  • [2024-10-31 22:13:58]
  • hack成功,自动添加数据
  • (/hack/1096)
  • [2024-10-31 22:09:20]
  • 自动重测本题所有获得100分的提交记录
  • 测评结果:100
  • 用时:80ms
  • 内存:3636kb
  • [2024-10-31 22:00:43]
  • hack成功,自动添加数据
  • (/hack/1095)
  • [2024-10-24 09:35:26]
  • 评测
  • 测评结果:100
  • 用时:83ms
  • 内存:3832kb
  • [2024-10-24 09:35:26]
  • 提交

answer

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

using ull = unsigned long long;

bool is_prime(ull n) {
	if(n == 2) { return true; }
	if(n % 2 == 0) { return false; }
	auto internal_pow = [&](ull x, ull y) {
		ull r = 1;
		__uint128_t c = x;
		for(; y; y >>= 1, c = c * c % n) {
		if(y & 1) { r = __uint128_t(r) * c % n; }
		}
		return r;
	};
	auto MillerRabin = [&](ull a) {
		if(n <= a) { return true; }
		int e = __builtin_ctzll(n - 1);
		ull z = internal_pow(a, (n - 1) >> e);
		if(z == 1 || z == n - 1) { return true; }
		while(--e) {
		z = __uint128_t(z) * z % n;
		if(z == 1) { return false; }
		if(z == n - 1) { return true; }
		}
		return false;
	};
	vector<ull> cur;
	if(n < 4759123141) cur = vector<ull>{2, 7, 61};
	else cur = vector<ull>{2, 325, 9375, 28178, 450775, 9780504, 1795265022};
	return all_of(cur.begin(), cur.end(), [&](auto x) { return MillerRabin(x); });
}

struct Montgomery {
  	ull mod, R;

 public:
	Montgomery(ull n): mod(n), R(n) {
		for(int i = 0; i < 5; i++) { R *= 2 - mod * R; }
	}
	ull fma(ull a, ull b, ull c) const {
		const __uint128_t d = __uint128_t(a) * b;
		const ull e = c + mod + (d >> 64);
		const ull f = ull(d) * R;
		const ull g = (__uint128_t(f) * mod) >> 64;
		return e - g;
	}
	ull mul(ull a, ull b) const { return fma(a, b, 0); }
};

ull PollardRho(ull n) {
	if(n % 2 == 0) { return 2; }
	const Montgomery m(n);
	constexpr ull C1 = 1, C2 = 2, M = 512;
	ull Z1 = 1, Z2 = 2;
 retry:
	ull z1 = Z1, z2 = Z2;
	for(unsigned k = M;; k <<= 1) {
		const ull x1 = z1 + n, x2 = z2 + n;
		for(unsigned j = 0; j < k; j += M) {
		const ull y1 = z1, y2 = z2;
		ull q1 = 1, q2 = 2;
		z1 = m.fma(z1, z1, C1), z2 = m.fma(z2, z2, C2);
		for(unsigned i = 0; i < M; i++) {
			const ull t1 = x1 - z1, t2 = x2 - z2;
			z1 = m.fma(z1, z1, C1), z2 = m.fma(z2, z2, C2);
			q1 = m.mul(q1, t1), q2 = m.mul(q2, t2);
		}
		q1 = m.mul(q1, x1 - z1), q2 = m.mul(q2, x2 - z2);
		const ull q3 = m.mul(q1, q2), g3 = gcd(n, q3);
		if(g3 == 1) { continue; }
		if(g3 != n) { return g3; }
		const ull g1 = gcd(n, q1), g2 = gcd(n, q2);
		const ull C = g1 != 1 ? C1 : C2, x = g1 != 1 ? x1 : x2;
		ull z = g1 != 1 ? y1 : y2, g = g1 != 1 ? g1 : g2;
		if(g == n) {
			do {
			z = m.fma(z, z, C);
			g = gcd(n, x - z);
			} while(g == 1);
		}
		if(g != n) { return g; }
		Z1 += 2, Z2 += 2;
		goto retry;
		}
	}
}

vector<ull> PrimeFactorize(ull n) {
	vector<ull> r;
	auto rec = [&](auto &&rec, ull n, vector<ull> &r) -> void {
		if(n <= 1) { return; }
		if(is_prime(n)) {
		r.emplace_back(n);
		return;
		}
		const ull p = PollardRho(n);
		rec(rec, p, r);
		rec(rec, n / p, r);
	};
	rec(rec, n, r);
	sort(r.begin(), r.end());
	return r;
}

vector<pair<ll, ll>> Prime(ll n) {
    auto ans = PrimeFactorize(n);
    vector<pair<ll, ll>> cur;
    for(ll i = 0; i < ans.size(); ++i){
        ll e = 1;
        while(i + 1 < ans.size() && ans[i + 1] == ans[i]) ++e, ++i;
        cur.push_back({ans[i], e});
    }
    return cur;
}

void solve() {
	ll N;
	cin >> N;

	auto ans = PrimeFactorize(N);

	map<ll, int> mp;
    for (auto x : ans) {
        mp[x]++;
    }
    ll res = 1;
    for (auto& [x, val] : mp) {
        res *= (2LL * val + 1);
    }
    cout << (res + 1) / 2 << '\n';
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll t;
	cin >> t;
	while(t--) { solve(); }
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3864kb

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: 0
Accepted
time: 83ms
memory: 3572kb

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:

29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
29525
...

result:

ok 2000 lines

Test #3:

score: 0
Accepted
time: 21ms
memory: 3628kb

input:

2000
1763047095
79735483
1016286871
2864801397
2327774116
2668010360
3469893354
3634459021
1613699068
781737219
574741575
2763134701
1458502604
1822260248
2281150332
2924219311
2493931196
3735904708
158802001
2006921221
729928782
1974841034
727412600
2873393292
1291087179
2741607663
1893408215
29827...

output:

14
5
2
5
23
95
68
14
8
68
203
14
23
32
38
41
8
8
14
2
608
41
158
338
23
41
14
5
14
41
14
203
41
14
17
446
5
53
59
878
2
14
365
203
14
203
2
122
32
95
41
41
5
23
14
41
5
5
14
122
23
203
608
23
41
122
2
14
95
2
68
41
203
14
230
41
68
23
50
14
32
14
8
5
5
5
68
68
122
293
473
5
41
41
14
2
14
14
5
2
122
...

result:

ok 2000 lines

Extra Test:

score: 0
Extra Test Passed