QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#246750 | #3379. Inverse Divisor Sums | rootcucu | AC ✓ | 776ms | 3780kb | C++17 | 2.5kb | 2023-11-11 04:16:56 | 2023-11-11 04:16:58 |
Judging History
answer
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
const ll M = 32700;
const ll M2 = 1'000'000'000;
//const ll M = 50;
//const ll M2 = 2500;
int a[M];
// pair<pp sum,prime power>
vector<vector<pair<ll,ll>>> x;
vector<ll> vec_ans;
vector<ll> primes;
void f(int i, ll n, ll p){
/*
if (i == 0)
cout << "x.size() " << x.size() << "\n";
*/
if (n == 1){
vec_ans.push_back(p);
return;
}
if (i == size(x))
return;
ll pre = 0;
for (auto [v,w]:x[i]){
if (v > n)
break;
if (n % v == 0){
f(i+1, n / v, p * w);
}
pre = v;
}
}
void g(ll n, ll p){
// i : prime in primes
x.clear();
for (int i:primes){
vector<pair<ll,ll>> y;
ll power_sum = 1;
ll po = 1;
while (power_sum < M2){
if (n % power_sum == 0)
y.push_back({power_sum, po});
po *= i;
power_sum += po;
}
if (y.size() > 1)
x.push_back(y);
}
f(0, n, p);
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0);
int cnt = 0;
for (int i = 2; i < M; i++){
if (a[i] == 1)
continue;
for (int j = i*i; j < M; j+= i)
a[j] = 1;
primes.push_back(i);
}
int t; cin >> t;
while (t--){
// n 이 32'000 이상의 소수 + 1을 인수로 가질 경우.
ll n; cin >> n;
vec_ans.clear();
g(n, 1);
for (int d = 1; d < M; d++){
if (n % d == 0){
ll m = n / d;
if (m > M){
int pri = 1;
//m-1 이 소수인지 검사.
for (int v:primes){
if ((m - 1) % v == 0){
pri = 0;
break;
}
}
if (pri){
// cout << "n/m " << 1.*n / m << ", prime " << (m-1) << "\n";
g(n/m, m-1);
}
}
}
}
int m = size(vec_ans);
if (m == 0)
cout << "none!\n";
else {
sort(vec_ans.begin(), vec_ans.end());
cout << vec_ans[0];
for (int i = 1; i < m; i++){
cout << " " << vec_ans[i];
}
cout << "\n";
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 776ms
memory: 3780kb
input:
100 7 2 126 1524 7257600 87091200 958003200 1000000000 1 993686400 972159504 241678080 788971644 33506784 127518104 48058050 321231024 448498080 922494776 423675301 483381360 583640640 983450160 230320872 327515370 176938080 472362480 344695601 261730884 339812160 192054734 813374900 541898100 23480...
output:
4 none! 68 82 704 1083 1523 1670760 1784160 1811040 1851360 1863540 1887840 1897560 1918620 1929312 1953504 1954680 1983960 1984920 2012640 2021880 2031960 2061720 2069280 2074380 2081160 2081640 2095080 2103192 2104440 2116920 2126280 2132460 2133432 2138136 2146620 2150040 2171232 2179680 2180220 ...
result:
ok 100 lines
Extra Test:
score: 0
Extra Test Passed