QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#634518#9309. GraphKafuuChinocppAC ✓335ms14400kbC++142.2kb2024-10-12 17:30:002024-10-12 17:30:02

Judging History

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

  • [2024-10-12 17:30:02]
  • 评测
  • 测评结果:AC
  • 用时:335ms
  • 内存:14400kb
  • [2024-10-12 17:30:00]
  • 提交

answer

#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

const int max1 = 316230;
const int mod = 998244353;

long long n;

bool is_not_prime[max1 + 5];
int prime[max1 + 5], total;

void Get_Prime ()
{
    for ( int i = 2; i <= max1; i ++ )
    {
        if ( !is_not_prime[i] )
            prime[++total] = i;
        
        for ( int j = 1; j <= total && i * prime[j] <= max1; j ++ )
        {
            is_not_prime[i * prime[j]] = true;
            if ( !(i % prime[j]) )
                break;
        }
    }
    return;
}

long long w[max1 * 2 + 5], f[max1 * 2 + 5], cnt;
int id1[max1 + 5], id2[max1 + 5];

int Quick_Power ( int base, long long p )
{
    int res = 1;
    while ( p )
    {
        if ( p & 1 )
            res = 1LL * res * base % mod;
        p >>= 1;
        base = 1LL * base * base % mod;
    }
    return res;
}

int Calc ( long long m )
{
    if ( m == 1 || m == 2 )
        return 1;
    if ( m == 3 )
        return 3;
    
    int v1 = m <= max1 ? id1[m] : id2[n / m];
    int v2 = m / 2 <= max1 ? id1[m / 2] : id2[n / (m / 2)];

    long long c = f[v1] - f[v2];

    return 1LL * Quick_Power(m % mod, c) * ((m - c - 1) % mod) % mod;
}

int main ()
{
    Get_Prime();
    scanf("%lld", &n);

    for ( long long L = 1, R; L <= n; L = R + 1 )
    {
        R = n / (n / L);

        w[++cnt] = n / L;
        f[cnt] = w[cnt] - 1;

        if ( w[cnt] <= max1 )
            id1[w[cnt]] = cnt;
        else
            id2[n / w[cnt]] = cnt;
    }

    for ( int i = 1; i <= total; i ++ )
    {
        if ( 1LL * prime[i] * prime[i] > n )
            break;
        
        for ( int j = 1; j <= cnt; j ++ )
        {
            if ( 1LL * prime[i] * prime[i] > w[j] )
                break;
            
            int v = w[j] / prime[i] <= max1 ? id1[w[j] / prime[i]] : id2[n / (w[j] / prime[i])];

            f[j] = f[j] - f[v] + i - 1;
        }
    }

    int ans = 1;
    for ( long long L = 1, R; L <= n; L = R + 1 )
    {
        R = n / (n / L);

        int val = Calc(n / L);
        ans = 1LL * ans * Quick_Power(val, R - L + 1) % mod;
    }

    printf("%d\n", ans);

    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 4100kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

score: 0
Accepted
time: 2ms
memory: 4012kb

input:

2

output:

1

result:

ok answer is '1'

Test #3:

score: 0
Accepted
time: 2ms
memory: 4052kb

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 2ms
memory: 4088kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

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

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

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

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

score: 0
Accepted
time: 2ms
memory: 4268kb

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 7ms
memory: 7512kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 18ms
memory: 5788kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

score: 0
Accepted
time: 17ms
memory: 5840kb

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 24ms
memory: 7052kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 50ms
memory: 8260kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 117ms
memory: 11832kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 224ms
memory: 12732kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 305ms
memory: 13816kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 330ms
memory: 14356kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 331ms
memory: 14400kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 335ms
memory: 14344kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed