QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#550501 | #9248. An Easy Math Problem | ucup-team133# | TL | 0ms | 3604kb | C++23 | 4.9kb | 2024-09-07 13:13:36 | 2024-09-07 13:13:37 |
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-09-07 13:13:36]
- Submitted
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for (auto& e : v) {
is >> e;
}
return is;
}
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
for (std::string_view sep = ""; const auto& e : v) {
os << std::exchange(sep, " ") << e;
}
return os;
}
template <class T, class U = T> bool chmin(T& x, U&& y) {
return y < x and (x = std::forward<U>(y), true);
}
template <class T, class U = T> bool chmax(T& x, U&& y) {
return x < y and (x = std::forward<U>(y), true);
}
template <class T> void mkuni(std::vector<T>& v) {
std::ranges::sort(v);
auto result = std::ranges::unique(v);
v.erase(result.begin(), result.end());
}
template <class T> int lwb(const std::vector<T>& v, const T& x) {
return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}
namespace elementary_math {
template <typename T> std::vector<T> divisor(T n) {
std::vector<T> res;
for (T i = 1; i * i <= n; i++) {
if (n % i == 0) {
res.emplace_back(i);
if (i * i != n) res.emplace_back(n / i);
}
}
return res;
}
template <typename T> std::vector<std::pair<T, int>> prime_factor(T n) {
std::vector<std::pair<T, int>> res;
for (T p = 2; p * p <= n; p++) {
if (n % p == 0) {
res.emplace_back(p, 0);
while (n % p == 0) {
res.back().second++;
n /= p;
}
}
}
if (n > 1) res.emplace_back(n, 1);
return res;
}
std::vector<int> osa_k(int n) {
std::vector<int> min_factor(n + 1, 0);
for (int i = 2; i <= n; i++) {
if (min_factor[i]) continue;
for (int j = i; j <= n; j += i) {
if (!min_factor[j]) {
min_factor[j] = i;
}
}
}
return min_factor;
}
std::vector<int> prime_factor(const std::vector<int>& min_factor, int n) {
std::vector<int> res;
while (n > 1) {
res.emplace_back(min_factor[n]);
n /= min_factor[n];
}
return res;
}
long long modpow(long long x, long long n, long long mod) {
assert(0 <= n && 1 <= mod && mod < (1LL << 31));
if (mod == 1) return 0;
x %= mod;
long long res = 1;
while (n > 0) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
long long extgcd(long long a, long long b, long long& x, long long& y) {
long long d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else
x = 1, y = 0;
return d;
}
long long inv_mod(long long a, long long mod) {
assert(1 <= mod);
long long x, y;
if (extgcd(a, mod, x, y) != 1) return -1;
return (mod + x % mod) % mod;
}
template <typename T> T euler_phi(T n) {
auto pf = prime_factor(n);
T res = n;
for (const auto& p : pf) {
res /= p.first;
res *= p.first - 1;
}
return res;
}
std::vector<int> euler_phi_table(int n) {
std::vector<int> res(n + 1, 0);
std::iota(res.begin(), res.end(), 0);
for (int i = 2; i <= n; i++) {
if (res[i] != i) continue;
for (int j = i; j <= n; j += i) res[j] = res[j] / i * (i - 1);
}
return res;
}
// minimum i > 0 s.t. x^i \equiv 1 \pmod{m}
template <typename T> T order(T x, T m) {
T n = euler_phi(m);
auto cand = divisor(n);
std::sort(cand.begin(), cand.end());
for (auto& i : cand) {
if (modpow(x, i, m) == 1) {
return i;
}
}
return -1;
}
template <typename T> std::vector<std::tuple<T, T, T>> quotient_ranges(T n) {
std::vector<std::tuple<T, T, T>> res;
T m = 1;
for (; m * m <= n; m++) res.emplace_back(m, m, n / m);
for (; m >= 1; m--) {
T l = n / (m + 1) + 1, r = n / m;
if (l <= r and std::get<1>(res.back()) < l) res.emplace_back(l, r, n / l);
}
return res;
}
} // namespace elementary_math
using ll = long long;
using namespace std;
void solve() {
ll n;
cin >> n;
auto ps = elementary_math::prime_factor(n);
set<pair<ll, ll>> s;
auto dfs = [&](auto self, int d, ll p, ll q) -> void {
if (d == int(ps.size())) {
if (p > q) return;
ll g = gcd(p, q);
s.emplace(p / g, q / g);
return;
}
auto [x, y] = ps[d];
for (int i = 0; i <= y; i++) {
for (int j = 0; i + j <= y; j++) {
ll np = p, nq = q;
for (int k = 0; k < i; k++) np *= x;
for (int k = 0; k < j; k++) nq *= x;
self(self, d + 1, np, nq);
}
}
};
dfs(dfs, 0, 1, 1);
int ans = s.size();
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int q;
cin >> q;
for (; q--;) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
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...