QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#770520#9597. Grade 2yeah14WA 0ms34876kbC++172.8kb2024-11-21 22:11:392024-11-21 22:11:40

Judging History

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

  • [2024-11-21 22:11:40]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:34876kb
  • [2024-11-21 22:11:39]
  • 提交

answer

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define i128 _int128
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define int long long

const ll INF = 0x3f3f3f3f;
const int N = 4e6 + 9, M = 1e9 + 9;
const ll mod = 998244353;

int read()
{
    int s = 0, w = 1;
    char c = getchar();
    while (!isdigit(c))
        (c == '-') ? w = -1 : w = 1, c = getchar();
    while (isdigit(c))
        s = (s << 1) + (s << 3) + (c ^ 48), c = getchar();
    return s * w;
}

int qpow(int a, int b)
{
    a %= mod;
    int res = 1;
    while (b)
    {
        if (b & 1)
        {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return res % mod;
}

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    else
        return gcd(b, a % b);
}

// int inverse(int a){
//     a%=mod;
//     return qpow(fac[a%mod],mod-2)%mod;
// }

// int C(int n,int r){
//     n%=mod,r%=mod;
//     if(r>n)return 0;
//     return ((fac[n%mod]*inverse(r))%mod*inverse(n-r))%mod;
// }

// int Lucas(int n,int r){
//     if(r==0)return 1;
//     return C(n%mod,r%mod)%mod*Lucas(n/mod,r/mod)%mod;
// }

int x, n, mini_sum, l, r, ans;
map<int, int> res;
int prefix[N];

void solve()
{
    cin >> x >> n;
    int p = 1;
    ans = 0;
    memset(prefix, 0, sizeof(prefix));
    while (p < x)
        p *= 2;
    int fid = 0, lid = 0;
    for (int i = 1; i <= p; ++i)
    {
        if (gcd(((i * x) ^ x), x) == 1)
        {
            // cout<<i<<endl;
            res[i] = 1;
            mini_sum++;
            if (fid == 0)
                fid = i;
            lid = i;
        }
        prefix[i] = prefix[i - 1] + res[i];
    }
    // for(int i=1;i<=p;++i){
    //     cout<<i<<'-'<<prefix[i]<<endl;
    // }
    // cout<<fid<<' '<<lid<<endl;
    while (n--)
    {
        cin >> l >> r;
        if (!x & 1)
            ans = 0;
        else
        {
            ans = prefix[r % p] - prefix[l % p - 1] + mini_sum * ((r - l) / p);
            // if(r%p!=lid)r=r-r%p;
            // if(l%p!=fid)l+=p-l%p;
            // caseout<<l<<' '<<r;
            // if(l<r)ans+=mini_sum;
            if (l - l % p +   p <= r%p)ans += mini_sum;
            else if (ans < 0)ans += mini_sum;
            cout << ans << endl;
        }
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int _ = 1;
    // fac[0]=1;
    // for(int i=1;i<=N-9;++i)fac[i]=(fac[i-1]*i)%mod;
    // cin>>_;

    while (_--)
        solve();

    return 0;
}
/*
255255 10
165055 339075075373
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 34876kb

input:

15 2
1 4
11 4514

output:

2
2244

result:

wrong answer 2nd lines differ - expected: '2252', found: '2244'