QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#252316#7707. Rikka with Proper FractionsSolitaryDream#WA 1113ms54960kbC++171.5kb2023-11-15 18:08:472023-11-15 18:08:47

Judging History

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

  • [2023-11-15 18:08:47]
  • 评测
  • 测评结果:WA
  • 用时:1113ms
  • 内存:54960kb
  • [2023-11-15 18:08:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,t) for(int i=(s),_t=(t); i<=_t; ++i)
#define DOR(i,s,t) for(int i=(s),_t=(t); i>=_t; --i)
typedef long long ll;
const int N=4e6+50;
const int Mod=998244353;
vector<int> prim;
bool mark[N];
int mo[N];
ll Mo[N];
unordered_map<ll,ll> MO;
void Sieve() {
    mo[1]=1;
    FOR(i,2,N-1) {
        if(!mark[i]) {
            prim.push_back(i);
            mo[i]=-1;
        }
        for(auto p: prim) {
            int x=i*p;
            if(x>=N) break;
            mark[x]=1;
            if(i%p==0) break;
            else mo[x]=-mo[i];
        }
    }
    FOR(i,1,N-1) Mo[i]=Mo[i-1]+mo[i];
}
ll sum_mo(ll n) {
    if(n<N) return Mo[n];
    if(MO.count(n)) return MO[n];
    ll t=1;
    for(ll i=2,j; i<=n; i=j+1) {
        j=n/(n/i);
        t-=(j-i+1)*sum_mo(n/i);
    }
    return MO[n]=t;
}
ll g(ll n,ll a,ll b,ll m) {
    if(b==0) return n*(a/m);
    if(a>=m) return n*(a/m)+g(n,a%m,b,m);
    if(b>=m) return (n-1)*n/2*(b/m)+g(n,a,b%m,m);
    return g((a+b*n)/m,(a+b*n)%m,m,b);
}
ll a,b,c,d;
ll f(ll n) {
    return g(n,c,c,d)-g(n,a-1,a,b);
}
void solve() {
    ll n;
    cin >> n >> a >> b >> c >> d;
    ll res=0;
    for(ll l=1,r; l<=n; l=r+1) {
        r=n/(n/l);
        res=(res+(f(n/l)%Mod)*((sum_mo(r)-sum_mo(l-1))%Mod))%Mod;
    }
    if(res<0) res+=Mod;
    cout << res << '\n';
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Sieve();
    int T;
    cin >> T;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 23ms
memory: 54908kb

input:

3
5 1 2 3 4
10 1 2 7 9
1000000 2 13 10000 10001

output:

4
10
620740490

result:

ok 3 number(s): "4 10 620740490"

Test #2:

score: -100
Wrong Answer
time: 1113ms
memory: 54960kb

input:

1000
9999999448 3976682 23995239 42975039 59844971
9999999773 10061920 59580251 27956416 32398077
9999999574 21925008 70974599 17950010 34959827
999974 65309629 81242992 20532129 22849421
999872 7314909 34345433 23595307 37296176
999323 13651129 23152646 64013836 67070163
999227 1925038 74238199 496...

output:

411097149
723014325
101716902
834268785
753719757
934180309
508263038
1887553
718279083
340325139
884901498
889619070
655410132
70251681
896081437
207561678
919483894
690447888
140498884
854489432
809737270
451839051
214402115
839519025
881060889
804962252
942008860
367994218
928840147
329819190
959...

result:

wrong answer 1st numbers differ - expected: '344904706', found: '411097149'