QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#208874 | #4478. Jo loves counting | 11d10xy | WA | 364ms | 30868kb | C++14 | 1.0kb | 2023-10-09 21:38:04 | 2023-10-09 21:38:05 |
Judging History
answer
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using lll=__int128;
constexpr ll mod=29ll<<57|1,mxn=1e12;
constexpr int sqn=1e6;
auto ml=[](ll x,ll y)->ll{return(lll)x*y%mod;};
auto inv=[](ll p){ll res=1,t=mod-2;for(;t;t>>=1,p=ml(p,p))if(t&1)res=ml(res,p);return res;};
auto sum=[](ll n)->ll{return(lll)n*(n+1)/2%mod;};
int p[sqn+10],pt;
basic_string<ll>h[79010],pp[79010];
ll n;
ll dfs(ll now,ll v,int i){
if(i>pt||now>n/pp[i][2])return ml(v,sum(n/now));
ll res=dfs(now,v,i+1);
for(int j=2;j<pp[i].size()&&now*pp[i][j]<=n;j++)
(res+=dfs(now*pp[i][j],ml(v,h[i][j]),i+1))%=mod;
return res;
}
int main(){
for(int i=2;i<=sqn;i++)
if(!p[i])for(int j=p[++pt]=i;j<=sqn;j+=i)p[j]=1;
for(int i=1;i<=pt;i++){
pp[i]=h[i]={1};
ll now=1;
for(int j=1;pp[i][j-1]*p[i]<=mxn;j++)
now=ml(now,p[i]),pp[i]+=pp[i][j-1]*p[i],
h[i]+=(ml(pp[i][j],inv(j))+mod-now)%mod,(now+=h[i][j])%=mod;
}
int T;
for(cin>>T;T--;)cin>>n,cout<<ml((sum(n)+dfs(1,1,1))%mod,inv(n))<<endl;
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 364ms
memory: 30868kb
input:
12 4 959139 9859 125987 209411 965585325539 213058376259 451941492387 690824608515 934002691939 1000000000000 1
output:
2089670227099910149 2544652967005915740 1531132428015613127 4112905740393139187 2210911161352349138 3734327733772621831 3166689709144126469 2205751357886278642 1440445927112024278 350512195591528730 3189354461630700470 2
result:
wrong answer 1st lines differ - expected: '2', found: '2089670227099910149'