QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#605130#8761. 另一个计数问题AAA___WA 687ms81964kbC++144.0kb2024-10-02 15:41:262024-10-02 15:41:32

Judging History

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

  • [2024-10-02 15:41:32]
  • 评测
  • 测评结果:WA
  • 用时:687ms
  • 内存:81964kb
  • [2024-10-02 15:41:26]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<stack>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<map>
#include<string>
#include<vector>
#include<array>
#include<functional>
#define int long long
using namespace std;
typedef long long ll;
ll highbit(ll x){
    ll ans=2;
    int num=1;
    while(x){
        x>>=2;
        ans<<=2;
        num++;
    }
    return num;
}
ll lowbit(ll x){
    return x&(-x);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a>b?b:a;
}
ll gcd(ll x,ll y)
{
    if(y==1)
        return x;
    return gcd(y,x%y);
}
const int N = 1000010;
const ll mod=998244353;
const ll in2=499122177,in6=166374059;
ll md(ll x){
    return x%mod;
}
struct MIN1{
    ll prime[N], id1[N], id2[N], flag[N], ncnt, m;
    ll g[N], sum[N], a[N], T;
    ll n;
    int ID(ll x) {
        return x <= T ? id1[x] : id2[n / x];
    }
    ll calc(ll x) {
        return ((md(x * md(x + 1) )%mod)*in2%mod + mod - 1)%mod;
    }
    ll f(ll x) {
        return md(x);
    }
    ll init(ll n){
        T = sqrt(n);
        for (int i = 2; i <= T; i++) {
            if (!flag[i]) prime[++ncnt] = i, sum[ncnt] = md(sum[ncnt - 1] + i),sum[ncnt]=md(sum[ncnt]);
            
            for (int j = 1; j <= ncnt && i * prime[j] <= T; j++) {
                flag[i * prime[j]] = 1;
                if (i % prime[j] == 0) break;
            }
        }
        for (ll l = 1; l <= n; l = n / (n / l) + 1) {
            a[++m] = n / l;
            if (a[m] <= T) id1[a[m]] = m; else id2[n / a[m]] = m;
            g[m] = calc(a[m]);
        }
        for (int i = 1; i <= ncnt; i++)
            for (int j = 1; j <= m && (ll)prime[i] * prime[i] <= a[j]; j++)
                g[j] = g[j] 
                - ((ll)prime[i] * ((g[ID(a[j] / prime[i])] - sum[i - 1]+mod)%mod))%mod;
        return 0;
    }
    ll solve(ll x){
        if(x<=1){return x;}
        return n=x,init(n),g[ID(n)];
    }
}m11,m12;

struct MIN2{
    ll prime[N], id1[N], id2[N], flag[N], ncnt, m;
    ll g[N], sum[N], a[N], T;
    ll n;
    int ID(ll x) {
        return x <= T ? id1[x] : id2[n / x];
    }
    ll calc(ll x) {
        return md(md(md((md(x)*md(x+1))%mod)*md(md(2*x+1)))*in6%mod-1+mod);
    }
    ll f(ll x) {
        return x;
    }
    ll init(ll n){
        T = sqrt(n + 0.5);
        for (int i = 2; i <= T; i++) {
            if (!flag[i]) prime[++ncnt] = i, sum[ncnt] = sum[ncnt - 1] + md(i*i),sum[ncnt]=md(sum[ncnt]);
            for (int j = 1; j <= ncnt && i * prime[j] <= T; j++) {
                flag[i * prime[j]] = 1;
                if (i % prime[j] == 0) break;
            }
        }
        for (ll l = 1; l <= n; l = n / (n / l) + 1) {
            a[++m] = n / l;
            if (a[m] <= T) id1[a[m]] = m; else id2[n / a[m]] = m;
            g[m] = calc(a[m]);
        }
        for (int i = 1; i <= ncnt; i++)
            for (int j = 1; j <= m && (ll)prime[i] * prime[i] <= a[j]; j++)
                g[j] = g[j] - 
                md(md(prime[i]*prime[i]) * md(g[ID(a[j] / prime[i])] - sum[i - 1])),g[j]=(g[j]%mod+mod)%mod;
        return 0;
    }
    ll solve(ll x){
        if(x<=1){return x;}
        return n=x,init(n),g[ID(n)];
    }
}m21,m22;
signed main(void){
    unsigned int t;
//    freopen("input.in","r",stdin);
    ll n;
    cin>>n;
    m11.n=n;
    m12.n=((n+1)/2);
    m21.n=n;
    m22.n=((n+1)/2);
    ll pre1=m11.solve(n)-m12.solve(n/2);
    ll pre2=m21.solve(n)-m22.solve(n/2);
    pre1=md(md(pre1)+mod);
    pre2=md(md(pre2)+mod);
    ll ans=0;
    ll k=n%mod;
    ll buff=md(md(md((2+k)*(k-1))*in2)*md(md((2+k)*(k-1))*in2));
    buff-=md(md(md(k*md(k+1))*md(2*k+1))*in6);
    buff=md(md(buff)+mod);
    buff++;
    buff*=in2;
    buff%=mod;
    ans=md( md(md(md((2+k)*(k-1))*in2)*pre1)-pre2-md(md((pre1*pre1)-pre2)*in2)+mod );
    ans=(buff-ans+mod)%mod;
    cout<<ans<<endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

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

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

input:

6

output:

80

result:

ok 1 number(s): "80"

Test #4:

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

input:

7

output:

80

result:

ok 1 number(s): "80"

Test #5:

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

input:

8

output:

200

result:

ok 1 number(s): "200"

Test #6:

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

input:

9

output:

407

result:

ok 1 number(s): "407"

Test #7:

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

input:

10

output:

937

result:

ok 1 number(s): "937"

Test #8:

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

input:

79

output:

3224298

result:

ok 1 number(s): "3224298"

Test #9:

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

input:

123

output:

21077222

result:

ok 1 number(s): "21077222"

Test #10:

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

input:

158

output:

57411585

result:

ok 1 number(s): "57411585"

Test #11:

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

input:

285

output:

605750829

result:

ok 1 number(s): "605750829"

Test #12:

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

input:

355

output:

509863120

result:

ok 1 number(s): "509863120"

Test #13:

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

input:

484

output:

311440260

result:

ok 1 number(s): "311440260"

Test #14:

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

input:

520

output:

102191845

result:

ok 1 number(s): "102191845"

Test #15:

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

input:

706

output:

300787918

result:

ok 1 number(s): "300787918"

Test #16:

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

input:

747

output:

505062591

result:

ok 1 number(s): "505062591"

Test #17:

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

input:

784

output:

181810798

result:

ok 1 number(s): "181810798"

Test #18:

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

input:

76879

output:

716166793

result:

ok 1 number(s): "716166793"

Test #19:

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

input:

209295

output:

753032272

result:

ok 1 number(s): "753032272"

Test #20:

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

input:

220895

output:

874612082

result:

ok 1 number(s): "874612082"

Test #21:

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

input:

243390

output:

68635874

result:

ok 1 number(s): "68635874"

Test #22:

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

input:

414767

output:

862578797

result:

ok 1 number(s): "862578797"

Test #23:

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

input:

431662

output:

231728766

result:

ok 1 number(s): "231728766"

Test #24:

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

input:

521130

output:

106207351

result:

ok 1 number(s): "106207351"

Test #25:

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

input:

668419

output:

580625063

result:

ok 1 number(s): "580625063"

Test #26:

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

input:

700378

output:

790849562

result:

ok 1 number(s): "790849562"

Test #27:

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

input:

965876

output:

856082142

result:

ok 1 number(s): "856082142"

Test #28:

score: 0
Accepted
time: 56ms
memory: 42796kb

input:

998244350

output:

539142456

result:

ok 1 number(s): "539142456"

Test #29:

score: 0
Accepted
time: 56ms
memory: 42844kb

input:

998244351

output:

730264865

result:

ok 1 number(s): "730264865"

Test #30:

score: 0
Accepted
time: 52ms
memory: 42884kb

input:

998244352

output:

326703895

result:

ok 1 number(s): "326703895"

Test #31:

score: 0
Accepted
time: 56ms
memory: 45084kb

input:

998244353

output:

326703895

result:

ok 1 number(s): "326703895"

Test #32:

score: 0
Accepted
time: 56ms
memory: 41084kb

input:

998244354

output:

730264864

result:

ok 1 number(s): "730264864"

Test #33:

score: 0
Accepted
time: 60ms
memory: 45096kb

input:

998244355

output:

539142451

result:

ok 1 number(s): "539142451"

Test #34:

score: 0
Accepted
time: 52ms
memory: 42896kb

input:

998244356

output:

751581014

result:

ok 1 number(s): "751581014"

Test #35:

score: 0
Accepted
time: 92ms
memory: 50076kb

input:

2165916141

output:

216013547

result:

ok 1 number(s): "216013547"

Test #36:

score: 0
Accepted
time: 145ms
memory: 46836kb

input:

3550627266

output:

318019384

result:

ok 1 number(s): "318019384"

Test #37:

score: 0
Accepted
time: 328ms
memory: 64448kb

input:

11640239920

output:

137498099

result:

ok 1 number(s): "137498099"

Test #38:

score: 0
Accepted
time: 422ms
memory: 63460kb

input:

16191777349

output:

991399721

result:

ok 1 number(s): "991399721"

Test #39:

score: -100
Wrong Answer
time: 687ms
memory: 81964kb

input:

31326230483

output:

749906792

result:

wrong answer 1st numbers differ - expected: '99981147', found: '749906792'