QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#605003#8761. 另一个计数问题AAA___#WA 3ms34448kbC++203.9kb2024-10-02 14:59:062024-10-02 14:59:07

Judging History

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

  • [2024-10-02 14:59:07]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:34448kb
  • [2024-10-02 14:59:06]
  • 提交

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>
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;
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 (((x * (x + 1) )%mod)*in2 - 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] + i,
            sum[ncnt]%=mod;
            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;
        return 0;
    }
    ll solve(ll x){
        if(x<=1){return x;}
        return n=x,init(n),g[ID(n)];
    }
}m11,m12;
ll md(ll x){
    return x%mod;
}
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(x)*md(x+1))%mod)*(md(2*x+1))*in6-1);
    }
    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]%=mod;
            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]));
        return 0;
    }
    ll solve(ll x){
        if(x<=1){return x;}
        return n=x,init(n),g[ID(n)];
    }
}m21,m22;
int 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);
   // cout<<pre1<<endl;
    //cout<<pre2<<endl;
    pre1%=mod;
    pre2%=mod;
    ll ans=0;
    ll k=n%mod;
    ll buff=md(md((2+k)*(k-1))*in2)*md(md((2+k)*(k-1))*in2);
    buff-=md(md(md(k*(k+1))*(2*k+1))*in6);
    buff++;
    buff*=in2;
    buff%=mod;
    ans=md(md(md((2+k)*(k-1))*in2)*pre1)-pre2-md(md((pre1*pre1)-pre2)*in2);
    ans=buff-ans;
    ans%=mod;
    ans=(ans+mod)%mod;
    cout<<ans<<endl;
    return 0;
}

詳細信息

Test #1:

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

input:

4

output:

8

result:

ok 1 number(s): "8"

Test #2:

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

input:

5

output:

8

result:

ok 1 number(s): "8"

Test #3:

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

input:

6

output:

80

result:

ok 1 number(s): "80"

Test #4:

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

input:

7

output:

80

result:

ok 1 number(s): "80"

Test #5:

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

input:

8

output:

200

result:

ok 1 number(s): "200"

Test #6:

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

input:

9

output:

407

result:

ok 1 number(s): "407"

Test #7:

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

input:

10

output:

937

result:

ok 1 number(s): "937"

Test #8:

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

input:

79

output:

3224298

result:

ok 1 number(s): "3224298"

Test #9:

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

input:

123

output:

21077222

result:

ok 1 number(s): "21077222"

Test #10:

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

input:

158

output:

57411585

result:

ok 1 number(s): "57411585"

Test #11:

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

input:

285

output:

605750829

result:

ok 1 number(s): "605750829"

Test #12:

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

input:

355

output:

509863120

result:

ok 1 number(s): "509863120"

Test #13:

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

input:

484

output:

311440260

result:

ok 1 number(s): "311440260"

Test #14:

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

input:

520

output:

102191845

result:

ok 1 number(s): "102191845"

Test #15:

score: -100
Wrong Answer
time: 0ms
memory: 34260kb

input:

706

output:

433172804

result:

wrong answer 1st numbers differ - expected: '300787918', found: '433172804'