QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#246737#3379. Inverse Divisor SumsrootcucuTL 0ms0kbC++172.3kb2023-11-11 03:01:582023-11-11 03:01:58

Judging History

你现在查看的是最新测评结果

  • [2023-11-11 03:01:58]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-11-11 03:01:58]
  • 提交

answer

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int M = 32700;
const int M2 = 1'000'000'000;
//const int M = 50;
//const int M2 = 2500;
int a[M];
vector<vector<int>> x;
vector<int> vec_ans;
vector<int> primes;

void f(int i, int n, int p){
    if (n == 1){
        vec_ans.push_back(p);
        return;
    }
    if (i == size(x))
        return;
    int pre = 0;
    for (int v:x[i]){
        if (v > n)
            break;
        if (n % v == 0){
            int prime_power = v - pre;
            f(i+1, n / v, p * prime_power);
        }
        pre = v;
    }
}

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;
        primes.push_back(i);
        vector<int> y;
        for (int j = i*i; j < M; j+= i)
            a[j] = 1;
        int power_sum = 1;
        int po = 1;
        while (power_sum  < M2){
            y.push_back(power_sum);
            po *= i;
            power_sum += po;
            cnt++;
        }
        x.push_back(y);
    }

    int t; cin >> t;
    while (t--){
        // n 이 32'000 이상의 소수 + 1을 인수로 가질 경우.
        int n; cin >> n;
        vec_ans.clear();
        f(0, n, 1);
        for (int d = 1; d < M; d++){
            if (n % d == 0){
                int 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";
                        f(0, 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";
        }
    }
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

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: