当前位置: 首页 > news >正文

Atcoder - 460 - E - x + y ≡ x + y

Problem Statement

For positive integers aa and bb, define concat(a,b)concat(a,b) as the integer formed by writing aa and bb one after another. More formally, concat(a,b)concat(a,b) is defined as follows.

  • Let AA and BB be the strings formed by writing aa and bb in decimal, respectively. Let CC be the string formed by concatenating AA and BB in this order. The value of CC interpreted as an integer in decimal notation is concat(a,b)concat(a,b).

For example, if a=123a=123 and b=45b=45, then concat(a,b)=12345concat(a,b)=12345.

You are given positive integers NN and MM.
Find the number, modulo 998244353998244353, of pairs (x,y)(x,y) of positive integers not greater than NN such that concat(x,y)≡x+y(modM)concat(x,y)≡x+y(modM).

You are given TT test cases; solve each one.

Constraints

  • 1≤T≤1041≤T≤104
  • 1≤N≤10181≤N≤1018
  • 2≤M≤1092≤M≤109
  • All input values are integers.

Input

The input is given from Standard Input in the following format, where caseicasei denotes the ii-th test case:

TT
case1case1
case2case2
⋮⋮
caseTcaseT

Each test case is given in the following format:

NN MM

Output

Output TT lines. The ii-th line should contain the answer for the ii-th test case.
For each test case, output the number, modulo 998244353998244353, of pairs (x,y)(x,y) satisfying the condition.

Sample 1

Input复制 Output复制
4 3 2 123 456 20260530 460 123456789123456789 998244353 3 0 922576091 422081792

For the first test case, three pairs (x,y)(x,y) satisfy the condition: (2,1),(2,2),(2,3)(2,1),(2,2),(2,3).

算法分析

我们让N的位数是len,循环从1到len,len的最大值就是20。所以concat(a,b)=10^i*a+b模m和a+b模m相同。所以999……99(9的个数是i)的最大公约数和N同余,想到这一点代码就很好写出出来了。

AC代码

#include<bits/stdc++.h>
using namespace std;
const int mod = 998244353;
long long T,n,m;
int main(){scanf("%lld",&T);while(T--){scanf("%lld%lld",&n,&m);__int128 tm = m;__int128 sum = 0;__int128 x = 1;__int128 y = 0;for(int i = 1; i<=20; i++){sum = (sum+n/(m/__gcd(tm,10*x-1))*max(y,min(n-x+1,9*x)))%mod;//一个小小的压行^_^x*=10;}printf("%lld\n",(long long)sum%mod);//__int128官方是没有配输出的,所以要转long long。}return 0;
}

记得输出时要转long long!!!

http://www.zskr.cn/news/1462653.html

相关文章:

  • 工业相机选型与镜头参数完全指南:从原理到落地的关键决策
  • 揭秘文本转图表工具的效率革命:如何用代码思维重塑可视化工作流
  • WiiM Bar 7 月发布:479 美元打破高音质高价魔咒,拓展全屋音频生态
  • 明日方舟素材库终极指南:免费获取完整游戏资源实战秘籍
  • 3个技巧:用Draw.io Mermaid插件实现代码驱动图表设计
  • 3分钟免费激活IDM完整版:终极下载体验解锁指南
  • 年度必看!2026AI论文写作软件榜单(覆盖 99% 毕业论文需求)
  • 如何用智能视频分析工具将数小时视频压缩为5分钟可读报告
  • 保姆级教程:在Ubuntu 22.04上编译COLMAP 3.9,附赠6个常见编译错误的解决方案
  • 2026年 北京烘焙培训推荐榜单:家庭私房/摆摊甜品/专业裱花奶油蛋糕与日式面包综合口碑优选 - 品牌企业推荐师(官方)
  • 高性价比广告标识工厂怎么选?2026 省钱选型实用指南 - GrowthUME
  • 高效下载抖音视频:douyin-downloader完整实用指南
  • 航空复合纤维材料专用切割磨床厂家推荐:谁家能解决分层起毛的问题? - 资讯纵览
  • 计算机毕业设计之基于爬虫技术的电影推荐系统设计与实现
  • 从零搭建可信AI评估中台:基于NIST AI RMF v1.1的9模块实施路线图(含源码级配置清单)
  • 2026年10款精选论文AI智能降重工具实测:消AIGC特征实战对比实用指南 - 降AI小能手
  • AI工具如何真正驱动智能资产增值:3个被90%企业忽略的集成关键指标
  • MATLAB自动计算平行泊车安全起始位置范围并绘图
  • 2026 青岛黄金回收靠谱商家推荐|铂金白银 K 金金条首饰回收价格与门店指南 - 同城好物推荐官
  • DXVK内存优化完全指南:彻底解决游戏VRAM泄漏问题
  • 2026窗户漏水维修推荐:补漏剂/密封胶/服务商选型指南 - 资讯纵览
  • 2026年 上海/江苏实验室系统与家具设备实力厂家解析:通排风/变风量/新风系统及全钢/PP/不锈钢实验台 - 品牌企业推荐师(官方)
  • 2026年江苏实验室家具设备及通风柜制造企业:技术实力与安全可靠之选 - 品牌企业推荐师(官方)
  • 如何快速修复幻兽帕鲁跨平台存档迁移:终极GUID冲突解决方案
  • AI工具与智能融资整合落地指南(从API对接到风控模型嵌入的7大关键断点突破)
  • 2026年常州遗产继承律师怎么挑?5位专业律师实用指南 - 本地品牌推荐
  • 如何快速解决Windows热键冲突:专业工具使用指南
  • 3步掌握EPubBuilder:打造专业级在线电子书编辑器实战指南
  • 2026年实测10款降AIGC平台推荐:免费与付费全对比,毕业论文淡化AIGC痕迹必看 - 降AI小能手
  • 从引脚矩阵到万物互联:ESP32-Arduino如何重新定义物联网开发边界