跳到正文

题解

题解:AT_abc460_e [ABC460E] x + y ≡ x + y

__pyx__约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年5月31日
收录
2026年6月1日
更新
2026年11月15日
篇幅
约 2 分钟
获赞
1

版本

  1. v1当前

再复习中考我要变成痴呆儿。
红红红黑红紫紫。


yy 十进制下的位数为 ll,则 concat(x,y)=x×10l+y\mathrm{concat}(x, y) = x \times 10^l + y。

那么 x×10l+y≡x+y(modM)x \times 10^l + y \equiv x + y \pmod{M},即 x×10l≡x(modM)x \times 10^l \equiv x \pmod{M},即 x×(10l−1)≡0(modM)x \times (10^l-1) \equiv 0 \pmod{M}。

考虑到与 yy 的关系只有 ll 的大小,直接枚举 ll 来算就行了。

差不多是这样吧。怎么算看代码会比较好理解。

code
C++
#include<bits/stdc++.h>
#define int __int128
#define mod 998244353
using namespace std;
inline int read(){
	int x=0;char ch=getchar();
	int f=1;
	for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int ans=0;
signed main(){
	int t=read();
	while(t--){
		ans=0;
		int n=read(),m=read();
		int nn=n,w=0;
		while(nn){
			w++,nn/=10;
		}
		int ss=1;
		for(int i=1;i<=w;i++){
			ss*=10;
			int x=ss-1;
			int y=m/__gcd(m,x);
			int sum=(ss-ss/10)%mod;
			if(i==w)sum=(n-ss/10+1)%mod; 
			x=n/y;x%=mod; 
			ans+=sum*x%mod;
			ans%=mod;
		}
		cout<<(long long)ans<<'\n';
	}
	return 0;
}


原文
存档评论2 条抓取于