跳到正文

题解

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

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

文章信息

发布
2026年5月31日
收录
2026年5月31日
更新
2026年11月14日
篇幅
约 1 分钟

版本

  1. v1当前

设 len⁡(y)\operatorname{len}(y) 为 yy 在十进制下的位数。

原来的条件变为 x⋅10len⁡(y)+y≡x+y(modM)x \cdot 10^{\operatorname{len}(y)} + y \equiv x+y \pmod M,简单转化为 x⋅(10len⁡(y)−1)≡0(modM)x \cdot (10^{\operatorname{len}(y)} - 1) \equiv 0 \pmod M。

经典结论:方程 p⋅x≡0(modM)p \cdot x \equiv 0 \pmod M 满足 1≤x≤N1\le x \le N 的整数解有 ⌊N⋅gcd⁡(p,M)M⌋\left\lfloor \dfrac{N \cdot \gcd(p,M)}{M} \right\rfloor 个。

于是枚举 t=len⁡(y)t=\operatorname{len}(y),这样的 yy 共有 min⁡(N,10t−1)−10t+1(N≥10t)\min(N,10^t-1)-10^t+1(N \ge 10^t) 个。这样的 xx 共有 ⌊N⋅gcd⁡(10t−1,M)M⌋\left\lfloor\dfrac{N \cdot \gcd(10^t-1,M)}{M}\right\rfloor 个,乘起来即可。

submisson: https://atcoder.jp/contests/abc460/submissions/76270884

原文