QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#244605#4478. Jo loves countingucup-team203#ML 0ms0kbC++201.4kb2023-11-09 13:20:262023-11-09 13:20:27

Judging History

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

  • [2023-11-09 13:20:27]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2023-11-09 13:20:26]
  • 提交

answer

#include<bits/stdc++.h>
const int N=1e6+10;
using namespace std;
#define ll __int128_t
const ll Mod=(1ll<<57)*29ll+1;
ll Pow(ll n, ll k)
{
    ll res=1;
    for(ll x=n;k;x=x*x%Mod,k>>=1)if(k&1)res=res*x%Mod;
    return res;
}
int isp[N],p[N],tot;
ll M;
ll ans=0;
void calc(ll now,ll pos,ll h)
{
    if(p[pos]*p[pos]>M/now)
    {
        if(now==1)
        {
            ans+=(M*(M-1)/2)%Mod;
        }
        else
        {
            
            ans+=(h>0?1:-1)*now*Pow((h>0?h:-h),Mod-2)%Mod*(M/now)%Mod*(M/now+1)*Pow(2,Mod-2)%Mod;
            ans=(ans%Mod+Mod)%Mod;
            // printf("%lld %lld\n",(long long)now,(long long)(h>0?1:-1)*now*Pow(abs(h),Mod-2)%Mod);
        }
        // printf("%lld\n",(long long)ans);
        return;
    }
    calc(now,pos+1,h);
    for(int i=2,pj=p[pos]*p[pos];now<=M/pj;i++,pj*=p[pos])
    {
        calc(now*pj,pos+1,h*(-i*(i-1)));
    }
}
void solve()
{
    long long _;
    cin>>_;
    M=_;
    calc(1,0,1);
    ans=ans*Pow(2,Mod-2)%Mod;
    printf("%lld\n",(long long)ans);
}
int main()
{
    for (int i = 2; i <= N - 10; i++)
    {
        if (!isp[i])
            p[tot++] = i;
        for (int j = 0; i * p[j] < N && j < tot; j++)
        {
            isp[i * p[j]] = 1;
            if (i % p[j])
                ;
            else
                break;
        }
    }
    int T;
    cin>>T;
    while(T--)
    {
        solve();
    }
}

詳細信息

Test #1:

score: 0
Memory Limit Exceeded

input:

12
4
959139
9859
125987
209411
965585325539
213058376259
451941492387
690824608515
934002691939
1000000000000
1

output:

2
1063521647235962441
1654756389743847357
28123286989126918
186817287120753871

result: