QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#606277 | #8761. 另一个计数问题 | AAA___ | WA | 0ms | 34392kb | C++20 | 4.1kb | 2024-10-03 00:11:21 | 2024-10-03 00:11:22 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<stack>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<map>
#include<string>
#include<vector>
#include<array>
#include<functional>
#define int long long
using namespace std;
typedef long long ll;
ll highbit(ll x){
ll ans=2;
int num=1;
while(x){
x>>=2;
ans<<=2;
num++;
}
return num;
}
ll lowbit(ll x){
return x&(-x);
}
long long max(long long a,long long b){
return a>b?a:b;
}
long long min(long long a,long long b){
return a>b?b:a;
}
ll gcd(ll x,ll y)
{
if(y==1)
return x;
return gcd(y,x%y);
}
const int N = 1000010;
const ll mod=998244353;
const ll in2=499122177,in6=166374059;
ll md(ll x){
return x%mod;
}
struct MIN1{
ll prime[N], id1[N], id2[N], flag[N], ncnt, m;
ll g[N], sum[N], a[N], T;
ll n;
ll ID(ll x) {
return x <= T ? id1[x] : id2[n / x];
}
ll calc(ll x) {
x%=mod;
return ((md(x * md(x + 1) )%mod)*in2%mod + mod - 1)%mod;
}
ll f(ll x) {
return md(x);
}
ll init(ll n){
T = sqrt(n+0.5);
for (int i = 2; i <= T; i++) {
if (!flag[i]) prime[++ncnt] = i, sum[ncnt] = md(sum[ncnt - 1] + i),sum[ncnt]=md(sum[ncnt]);
for (int j = 1; j <= ncnt && i * prime[j] <= T; j++) {
flag[i * prime[j]] = 1;
if (i % prime[j] == 0) break;
}
}
for (ll l = 1; l <= n; l = n / (n / l) + 1) {
a[++m] = n / l;
if (a[m] <= T) id1[a[m]] = m; else id2[n / a[m]] = m;
g[m] = calc(a[m]);
}
for (ll i = 1; i <= ncnt; i++)
for (ll j = 1; j <= m && (ll)prime[i] * prime[i] <= a[j]; j++){
g[j] = g[j]
- ((ll)prime[i] * ((g[ID(a[j] / prime[i])] - sum[i - 1]+mod)%mod))%mod;
g[j]%=mod;
g[j]=(g[j]+mod)%mod;
}
return 0;
}
ll solve(ll x){
if(x<=1){return x;}
return n=x,init(n),g[ID(n)];
}
}m11,m12;
struct MIN2{
ll prime[N], id1[N], id2[N], flag[N], ncnt, m;
ll g[N], sum[N], a[N], T;
ll n;
ll ID(ll x) {
return x <= T ? id1[x] : id2[n / x];
}
ll calc(ll x) {
return md(md(md((md(x)*md(x+1))%mod)*md(md(2*x+1)))*in6%mod-1+mod);
}
ll f(ll x) {
return x;
}
ll init(ll n){
T = sqrt(n + 0.5);
for (int i = 2; i <= T; i++) {
if (!flag[i]) prime[++ncnt] = i, sum[ncnt] = sum[ncnt - 1] + md(i*i),sum[ncnt]=md(sum[ncnt]);
for (int j = 1; j <= ncnt && i * prime[j] <= T; j++) {
flag[i * prime[j]] = 1;
if (i % prime[j] == 0) break;
}
}
for (ll l = 1; l <= n; l = n / (n / l) + 1) {
a[++m] = n / l;
if (a[m] <= T) id1[a[m]] = m; else id2[n / a[m]] = m;
g[m] = calc(a[m]);
}
for (ll i = 1; i <= ncnt; i++)
for (ll j = 1; j <= m && prime[i] * prime[i] <= a[j]; j++){
g[j] = g[j] -
md(md(prime[i]*prime[i]) * md(g[ID(a[j] / prime[i])] - sum[i - 1])),g[j]=(g[j]%mod+mod)%mod;
g[j]%=mod;
g[j]=(g[j]+mod)%mod;
}
return 0;
}
ll solve(ll x){
if(x<=1){return x;}
return n=x,init(n),g[ID(n)];
}
}m21,m22;
signed main(void){
unsigned int t;
//freopen("input.in","r",stdin);
ll n;
cin>>n;
ll pre1=m11.solve(n)-m12.solve((n+1)/2);
ll pre2=m21.solve(n)-m22.solve((n+1)/2);
pre1=md(md(pre1)+mod);
pre2=md(md(pre2)+mod);
ll ans=0;
ll k=n%mod;
ll buff=md(md(md((2+k)*(k-1))*in2)*md(md((2+k)*(k-1))*in2));
buff-=md(md(md(k*md(k+1))*md(2*k+1))*in6);
buff=md(md(buff)+mod);
buff++;
buff*=in2;
buff%=mod;
ans=md( md(md(md((2+k)*(k-1))*in2)*pre1)-pre2-md(md((pre1*pre1)-pre2)*in2)+mod );
ans=(buff-ans+mod)%mod;
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 34392kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 34360kb
input:
5
output:
26
result:
wrong answer 1st numbers differ - expected: '8', found: '26'