【题解】P8152 「PMOI-5」破译の论

Sol

由题意可得,对于一次切割,会把一个矩形分成 \(n \times n\) 个矩形,所以每次切割会多出 \(n \times n-1\) 个矩形,那么答案即为 \(k \times (n \times n-1)+1\)

Code

//LYC_music yyds!
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0)
#define lowbit(x) (x&(-x))
#define int long long
using namespace std;
inline char gc()
{
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
int read()
{
	int pos=1,num=0;
	char ch=getchar();
	while (!isdigit(ch))
	{
		if (ch=='-') pos=-1;
		ch=getchar();
	}
	while (isdigit(ch))
	{
		num=num*10+(int)(ch-'0');
		ch=getchar();
	}
	return pos*num;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		write(-x);
		return;
	}
	if (x>=10) write(x/10);
	putchar(x%10+'0');
}
void writesp(int x)
{
	write(x);
	putchar(' ');
}
void writeln(int x)
{
	write(x);
	putchar('\n');
}
const int mod=998244353;
int n,k;
signed main()
{
	n=read(); k=read();
	writeln((k*((n*n-1+mod)%mod)+1)%mod);
}





posted @ 2022-02-14 08:02  dd_d  阅读(66)  评论(0)    收藏  举报