QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#710662#9309. GraphFrenkielAC ✓297ms27724kbC++201.9kb2024-11-04 20:57:122024-11-04 20:57:12

Judging History

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

  • [2024-11-04 20:57:12]
  • 评测
  • 测评结果:AC
  • 用时:297ms
  • 内存:27724kb
  • [2024-11-04 20:57:12]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<unordered_map>
using namespace std;
using LL = long long;

const int maxn = 1e6 + 5;
bool isPrime[maxn];
int primes[maxn], cnt;
void init(){
    isPrime[1] = 1;
    for(int i = 2; i < maxn; i++){
        if (!isPrime[i]) primes[++cnt] = i;
        for(int j = 1; i * primes[j] < maxn; j++){
            isPrime[i * primes[j]] = 1;
            if (i % primes[j] == 0) break;
        }
    }
} 

const int mod = 998244353;

int mul(int a, int b){
    return 1LL * a * b % mod;
}

int qpow(int a, LL b){
    int ans = 1;
    while(b){
        if (b & 1) ans = mul(ans, a);
        b >>= 1;
        a = mul(a, a);
    }
    return ans;
}

int id1[maxn], id2[maxn];
LL w[maxn];
LL g[maxn];
LL n;

int get(LL x){
    if (x < maxn) return id1[x];
    return id2[n / x];
}

int main(){

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    init();
    cin >> n;
    int m = 0;
    for(LL l = 1, r; l <= n; l = r + 1){
        LL val = n / l;
        w[++m] = val;
        r = n / val;
        if (val < maxn) id1[val] = m;
        else id2[n / val] = m;
        g[m] = val - 1;
    }

    for(int i = 1; 1LL * primes[i] * primes[i] <= n; i++){
        for(int j = 1; j <= m and 1LL * primes[i] * primes[i] <= w[j]; j++){
            g[j] = g[j] - (g[get(w[j] / primes[i])] - (i - 1));
        }
    }

    auto f = [&](LL m){
        if (m == 1) return 1;
        LL cnt = g[get(m)] - g[get(m / 2)];
        LL k = 1;
        k += cnt;
        if (m - cnt - 1 > 0) k += 1;
        int ans = qpow(m % mod, k - 2);
        if (m - cnt - 1 > 0) ans = mul(ans, (m - cnt - 1) % mod);
        return ans;
    };

    LL ans = 1;
    for(LL l = 1, r; l <= n; l = r + 1){
        r = n / (n / l);
        ans = mul(ans, qpow(f(n / l), r - l + 1));
    }
    cout << ans << '\n';

}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 10204kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 0ms
memory: 8920kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 5ms
memory: 9040kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 4ms
memory: 9108kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 5ms
memory: 10964kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 4ms
memory: 9044kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

score: 0
Accepted
time: 4ms
memory: 8976kb

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 5ms
memory: 13144kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

score: 0
Accepted
time: 5ms
memory: 11104kb

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

score: 0
Accepted
time: 6ms
memory: 13120kb

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 3ms
memory: 15260kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 16ms
memory: 17044kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 20ms
memory: 16960kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 27ms
memory: 16088kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 41ms
memory: 16920kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 104ms
memory: 21760kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 191ms
memory: 22232kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 262ms
memory: 24276kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 297ms
memory: 27408kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 289ms
memory: 26348kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 282ms
memory: 27724kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed