QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#682366 | #9248. An Easy Math Problem | OldMemory# | WA | 215ms | 3516kb | C++20 | 3.5kb | 2024-10-27 15:10:14 | 2024-10-27 15:10:18 |
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-27 15:10:14]
- Submitted
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
const double eps = 1e-8;
int mul(int a, int b, int m) {
return static_cast<__int128_t> (a) * b % m;
}
int power(int a, int b, int m) {
int res = 1 % m; a %= m;
while(b) {
if(b & 1) res = mul(res, a, m);
a = mul(a, a, m);
b >>= 1;
}
return res;
}
bool isprime(int n) {
if(n < 2) return false;
static constexpr int A[] = {2, 3, 5, 7, 11, 13, 17, 19, 23};
int s = __builtin_ctzll(n - 1);
int d = (n - 1) >> s;
for (auto a : A) {
if(a == n) return true;
int x = power(a, d, n);
if(x == 1 || x == n - 1) continue;
bool ok = false;
for (int i = 0; i < s - 1; ++i) {
x = mul(x, x, n);
if(x == n - 1) {
ok = true;
break;
}
}
if(!ok) return false;
}
return true;
}
vector<int> factorize(int n) {
vector<int> p;
function<void(int)> f = [&](int n) {
if(n <= 10000) {
for (int i =2; i * i <= n; ++i) {
for ( ; n % i == 0; n /= i) {
p.push_back(i);
}
}
if(n > 1) p.push_back(n);
return ;
}
if(isprime(n)) {
p.push_back(n);
return ;
}
auto g = [&](int x) {
return (mul(x, x, n) + 1) % n;
};
int x0 = 2;
while(true) {
int x = x0;
int y = x0;
int d = 1;
int power = 1, lam = 0;
int v = 1;
while(d == 1) {
y = g(y);
++lam;
v = mul(v, abs(x - y), n);
if(lam % 127 == 0) {
d = __gcd(v, n);
v = 1;
}
if(power == lam) {
x = y;
power *= 2;
lam = 0;
d = __gcd(v, n);
v = 1;
}
}
if(d != n) {
f(d);
f(n / d);
return ;
}
++x0;
}
};
f(n);
sort(p.begin(), p.end());
return p;
}
// int p2[30];
void solve() {
int n, res = 0; cin >> n;
if(n == 1) {
cout << 1 << '\n';
return;
}
vector<int> p = factorize(n);
vector<pair<int, int>> fac;
int sz = p.size();
for (int i = 0; i < sz; ++i) {
if(!i || p[i] != p[i - 1]) fac.push_back({p[i], 1});
else {
int k = fac.size();
fac[k - 1].second++;
}
}
int k = fac.size();
int cnt1 = 1;
for(int i = 0; i < k; i++) {
cnt1 = cnt1 * (fac[i].second + 1);
}
int ans = 0;
for(int i = 1; i < (1LL << k); i++) {
vector<int> ve;
int val = 1;
for(int j = 0; j < k; j++) {
if(i >> j & 1) {
ve.push_back(fac[j].second);
val *= fac[j].second;
}
}
if(ve.size() <= 1) continue;
int t = ve.size();
for(int j = 1; j < ve.size(); j++) {
ans += val * ((1LL << t) - 2);
}
}
cout << ans / 2 + cnt1 << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int t; cin >> t;
while(t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3516kb
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
Wrong Answer
time: 215ms
memory: 3484kb
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:
164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233 164233...
result:
wrong answer 1st lines differ - expected: '29525', found: '164233'