跳到正文

题解

题解:P13679 [IAMOI R2] 传奇模数

txc1201约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年5月14日
篇幅
约 1 分钟
题目
P13679

版本

  1. v1当前

原问题求:

(⌊1998244353⌋+⌊2998244353⌋+⋯+⌊n998244353⌋) mod 998244353\left(\lfloor\dfrac{1}{998244353}\rfloor+\lfloor\dfrac{2}{998244353}\rfloor+\dots+\lfloor\dfrac{n}{998244353}\rfloor\right)\bmod 998244353

1≤n≤10181\le n\le 10^{18}

可将问题转化为 :

n mod 998244353∗(n/998244353)n\bmod 998244353*(n/998244353)

把整个序列看成0 0 0 0 …0 0 0 0 1 1 1 1 1…1 1 1 1

令sum [i]为前ⅰ项和

则

sum(998244353∗k)mod998224353=0sum(998244353*k)mod998224353=0

所求部分为:

(n%mod+1)*(n/mod)

C++
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;
signed main()
{
	int n;
	cin>>n;
	if(n<mod)
	{
		cout<<0<<endl;
		return 0;
	}
	int ans=(n%mod+1)*(n/mod);
	cout<<ans%mod<<endl;
	return 0;
}

//蒟蒻的第一篇TJ

原文