QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#573016#9309. GraphMiniLongAC ✓311ms38116kbC++173.7kb2024-09-18 17:04:342024-09-18 17:04:35

Judging History

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

  • [2024-09-18 17:04:35]
  • 评测
  • 测评结果:AC
  • 用时:311ms
  • 内存:38116kb
  • [2024-09-18 17:04:34]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
    #ifdef ONLINE_JUDGE
    char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
    #define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
    #else
    #define get() getchar()
    #endif
    template<typename T> inline void read(T &t){
        T x = 0, f = 1;
        char c = getchar();
        while(!isdigit(c)){
            if(c == '-') f = -f;
            c = getchar();
        }
        while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
        t = x * f;
    }
    template<typename T, typename ... Args> inline void read(T &t, Args&... args){
        read(t);
        read(args...);
    }
    template<typename T> void write(T t){
        if(t < 0) putchar('-'), t = -t;
        if(t >= 10) write(t / 10);
        putchar(t % 10 + '0');
    }
    template<typename T, typename ... Args> void write(T t, Args... args){
        write(t), putchar(' '), write(args...);
    }
    template<typename T> void writeln(T t){
        write(t);
        puts("");
    }
    template<typename T> void writes(T t){
        write(t), putchar(' ');
    }
    #undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
    const ll mod = 998244353;
    ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
    void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
    void add(ll &x, ll y){x = (x + y) % mod;}
    void mul(ll &x, ll y){x = x * y % mod;}
    ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
    ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
    ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 1e6 + 5, _ = 1e6, B = 1e6;
ll n, cnt, prime[N], pre[N];
bool vis[N];
void init(){
    _rep(i, 2, _){
        pre[i] = pre[i - 1];
        if(!vis[i]) prime[++cnt] = i, pre[i]++;
        for(int j = 1; j <= cnt && prime[j] * i <= _; ++j){
            vis[i * prime[j]] = 1;
            if(i % prime[j] == 0) break;
        }
    }
}
ll m, w[N], g[N], id1[N], id2[N];
ll kkk;
ll S(ll m){
    return m <= _ ? g[id1[m]] : g[id2[n / m]];
}
ll calc(ll l, ll r){return S(r) - S(l - 1);}
ll f(ll m){
    kkk++;
    if(m == 1) return 1;
    ll t = calc(m / 2 + 1, m) + 1;
    if(t == m) return t == 1 ? 1 : ksm(m, t - 2);
    return (m - t) % mod * ksm(m, t - 1) % mod;
}
signed main(){
    init();
    read(n);
    for(ll l = 1, r = 0; l <= n; l = r + 1){
        r = n / (n / l);
        w[++m] = n / l;
        g[m] = (w[m] - 1);
        if(w[m] <= _) id1[w[m]] = m;
        else id2[n / w[m]] = m;
    }
    // debug("eee\n");
    _rep(i, 1, cnt){
        if(prime[i] * prime[i] > n) break;
        for(int j = 1; j <= m && prime[i] * prime[i] <= w[j]; ++j){
            int k = (w[j] / prime[i] <= _) ? id1[w[j] / prime[i]] : id2[n / (w[j] / prime[i])];
            g[j] += 1ll * (i - 1) - g[k];
        }
    }
    // debug("fff\n");
    ll ans = 1;
    for(ll l = 1, r = 0; l <= n; l = r + 1){
        r = n / (n / l);
        mul(ans, ksm(f(n / l), r - l + 1) % mod);
    }
    writeln(ans);
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 20288kb

input:

4

output:

8

result:

ok answer is '8'

Test #2:

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

input:

2

output:

1

result:

ok answer is '1'

Test #3:

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

input:

123

output:

671840470

result:

ok answer is '671840470'

Test #4:

score: 0
Accepted
time: 9ms
memory: 20728kb

input:

233

output:

353738465

result:

ok answer is '353738465'

Test #5:

score: 0
Accepted
time: 8ms
memory: 19488kb

input:

5981

output:

970246821

result:

ok answer is '970246821'

Test #6:

score: 0
Accepted
time: 8ms
memory: 21624kb

input:

86422

output:

897815688

result:

ok answer is '897815688'

Test #7:

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

input:

145444

output:

189843901

result:

ok answer is '189843901'

Test #8:

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

input:

901000

output:

819449452

result:

ok answer is '819449452'

Test #9:

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

input:

1000000

output:

113573943

result:

ok answer is '113573943'

Test #10:

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

input:

23333333

output:

949849384

result:

ok answer is '949849384'

Test #11:

score: 0
Accepted
time: 10ms
memory: 27076kb

input:

102850434

output:

604886751

result:

ok answer is '604886751'

Test #12:

score: 0
Accepted
time: 15ms
memory: 26384kb

input:

998244353

output:

0

result:

ok answer is '0'

Test #13:

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

input:

1000000007

output:

318420284

result:

ok answer is '318420284'

Test #14:

score: 0
Accepted
time: 32ms
memory: 26212kb

input:

2147483547

output:

688759898

result:

ok answer is '688759898'

Test #15:

score: 0
Accepted
time: 42ms
memory: 26100kb

input:

5120103302

output:

116870489

result:

ok answer is '116870489'

Test #16:

score: 0
Accepted
time: 99ms
memory: 30092kb

input:

19834593299

output:

523663743

result:

ok answer is '523663743'

Test #17:

score: 0
Accepted
time: 202ms
memory: 36252kb

input:

52500109238

output:

195086665

result:

ok answer is '195086665'

Test #18:

score: 0
Accepted
time: 275ms
memory: 34388kb

input:

84848352911

output:

107959260

result:

ok answer is '107959260'

Test #19:

score: 0
Accepted
time: 308ms
memory: 37580kb

input:

99824435322

output:

0

result:

ok answer is '0'

Test #20:

score: 0
Accepted
time: 309ms
memory: 38116kb

input:

99999999354

output:

316301711

result:

ok answer is '316301711'

Test #21:

score: 0
Accepted
time: 311ms
memory: 37772kb

input:

100000000000

output:

396843576

result:

ok answer is '396843576'

Extra Test:

score: 0
Extra Test Passed