QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#606255 | #8761. 另一个计数问题 | AAA___ | WA | 84ms | 46732kb | C++20 | 4.3kb | 2024-10-02 23:54:55 | 2024-10-02 23:54:55 |
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;
int ID(ll x) {
return x <= T ? id1[x] : id2[n / x];
}
ll calc(ll x) {
x%=mod;
return (((x * (x + 1) )%mod)*in2 - 1)%mod;
}
ll f(ll x) {
return x;
}
ll init(ll n){
T = sqrt(n + 0.5);
for (ll i = 2; i <= T; i++) {
if (!flag[i]) prime[++ncnt] = i, sum[ncnt] = sum[ncnt - 1] + i,
sum[ncnt]=md(sum[ncnt]);
for (ll 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;
int ID(ll x) {
return x <= T ? id1[x] : id2[n / x];
}
ll calc(ll x) {
x%=mod;
return md(md(md((md(x)*md(x+1))%mod)*(md(2*x+1)))*in6%mod-1+mod);
}
ll f(ll x) {
return x;
}
ll init(ll n){
T = sqrt(n + 0.5);
for (ll 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 (ll 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;
a[m]%=mod;
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] -
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;
m11.n=n;
m12.n=((n+1)/2);
m21.n=n;
m22.n=((n+1)/2);
ll pre1=m11.solve(n)-m12.solve(n/2);
ll pre2=m21.solve(n)-m22.solve(n/2);
pre1=md(md(pre1)+mod);
pre2=md(md(pre2)+mod);
pre1%=mod;
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((2+k)*(k-1))*in2)*pre1)-pre2-md(md((pre1*pre1)-pre2)*in2);
ans=buff-ans;
ans%=mod;
ans=(ans+mod)%mod;
cout<<ans<<endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 34404kb
input:
4
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 0ms
memory: 34408kb
input:
5
output:
8
result:
ok 1 number(s): "8"
Test #3:
score: 0
Accepted
time: 0ms
memory: 34312kb
input:
6
output:
80
result:
ok 1 number(s): "80"
Test #4:
score: 0
Accepted
time: 0ms
memory: 34404kb
input:
7
output:
80
result:
ok 1 number(s): "80"
Test #5:
score: 0
Accepted
time: 0ms
memory: 34384kb
input:
8
output:
200
result:
ok 1 number(s): "200"
Test #6:
score: 0
Accepted
time: 0ms
memory: 34512kb
input:
9
output:
407
result:
ok 1 number(s): "407"
Test #7:
score: 0
Accepted
time: 0ms
memory: 34440kb
input:
10
output:
937
result:
ok 1 number(s): "937"
Test #8:
score: 0
Accepted
time: 0ms
memory: 34428kb
input:
79
output:
3224298
result:
ok 1 number(s): "3224298"
Test #9:
score: 0
Accepted
time: 0ms
memory: 34488kb
input:
123
output:
21077222
result:
ok 1 number(s): "21077222"
Test #10:
score: 0
Accepted
time: 0ms
memory: 34404kb
input:
158
output:
57411585
result:
ok 1 number(s): "57411585"
Test #11:
score: 0
Accepted
time: 0ms
memory: 34340kb
input:
285
output:
605750829
result:
ok 1 number(s): "605750829"
Test #12:
score: 0
Accepted
time: 0ms
memory: 34404kb
input:
355
output:
509863120
result:
ok 1 number(s): "509863120"
Test #13:
score: 0
Accepted
time: 0ms
memory: 34488kb
input:
484
output:
311440260
result:
ok 1 number(s): "311440260"
Test #14:
score: 0
Accepted
time: 2ms
memory: 34324kb
input:
520
output:
102191845
result:
ok 1 number(s): "102191845"
Test #15:
score: 0
Accepted
time: 0ms
memory: 34456kb
input:
706
output:
300787918
result:
ok 1 number(s): "300787918"
Test #16:
score: 0
Accepted
time: 0ms
memory: 34324kb
input:
747
output:
505062591
result:
ok 1 number(s): "505062591"
Test #17:
score: 0
Accepted
time: 0ms
memory: 34408kb
input:
784
output:
181810798
result:
ok 1 number(s): "181810798"
Test #18:
score: 0
Accepted
time: 0ms
memory: 34376kb
input:
76879
output:
716166793
result:
ok 1 number(s): "716166793"
Test #19:
score: 0
Accepted
time: 0ms
memory: 34336kb
input:
209295
output:
753032272
result:
ok 1 number(s): "753032272"
Test #20:
score: 0
Accepted
time: 0ms
memory: 34392kb
input:
220895
output:
874612082
result:
ok 1 number(s): "874612082"
Test #21:
score: 0
Accepted
time: 0ms
memory: 34468kb
input:
243390
output:
68635874
result:
ok 1 number(s): "68635874"
Test #22:
score: 0
Accepted
time: 0ms
memory: 34600kb
input:
414767
output:
862578797
result:
ok 1 number(s): "862578797"
Test #23:
score: 0
Accepted
time: 0ms
memory: 34472kb
input:
431662
output:
231728766
result:
ok 1 number(s): "231728766"
Test #24:
score: 0
Accepted
time: 0ms
memory: 34488kb
input:
521130
output:
106207351
result:
ok 1 number(s): "106207351"
Test #25:
score: 0
Accepted
time: 5ms
memory: 34360kb
input:
668419
output:
580625063
result:
ok 1 number(s): "580625063"
Test #26:
score: 0
Accepted
time: 0ms
memory: 34368kb
input:
700378
output:
790849562
result:
ok 1 number(s): "790849562"
Test #27:
score: 0
Accepted
time: 2ms
memory: 34368kb
input:
965876
output:
856082142
result:
ok 1 number(s): "856082142"
Test #28:
score: 0
Accepted
time: 81ms
memory: 43016kb
input:
998244350
output:
539142456
result:
ok 1 number(s): "539142456"
Test #29:
score: 0
Accepted
time: 84ms
memory: 46732kb
input:
998244351
output:
730264865
result:
ok 1 number(s): "730264865"
Test #30:
score: 0
Accepted
time: 73ms
memory: 45008kb
input:
998244352
output:
326703895
result:
ok 1 number(s): "326703895"
Test #31:
score: -100
Wrong Answer
time: 52ms
memory: 42920kb
input:
998244353
output:
119095224
result:
wrong answer 1st numbers differ - expected: '326703895', found: '119095224'