QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#701893#7707. Rikka with Proper FractionsTheZoneAC ✓1697ms55104kbC++203.0kb2024-11-02 14:52:412024-11-02 14:53:19

Judging History

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

  • [2024-11-02 14:53:19]
  • 评测
  • 测评结果:AC
  • 用时:1697ms
  • 内存:55104kb
  • [2024-11-02 14:52:41]
  • 提交

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%Mod*(a/m)%Mod;
    if(a>=m) return (n%Mod*(a/m)+g(n,a%m,b,m))%Mod;
    if(b>=m) {
        if(n&1) return ((n-1)/2%Mod*(n%Mod)%Mod*(b/m)+g(n,a,b%m,m))%Mod;
        else return (n/2%Mod*((n-1)%Mod)%Mod*(b/m)+g(n,a,b%m,m))%Mod;
    }
    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;
}
/*#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%Mod*(a/m)%Mod;
    if(a>=m) return (n%Mod*(a/m)+g(n,a%m,b,m))%Mod;
    if(b>=m) {
        if(n&1) return ((n-1)/2%Mod*(n%Mod)%Mod*(b/m)+g(n,a,b%m,m))%Mod;
        else return (n/2%Mod*((n-1)%Mod)%Mod*(b/m)+g(n,a,b%m,m))%Mod;
    }
    return g((a+b*n)/m,(a+b*n)%m,m,b);
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: 15ms
memory: 54984kb

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: 0
Accepted
time: 1697ms
memory: 55104kb

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:

344904706
124603484
567742857
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:

ok 1000 numbers