当前位置: 首页 > 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.jsqmd.com/news/951036/

相关文章:

  • 别再让EMC测试卡脖子!硬件工程师必看的PCB布局与接地实战避坑指南
  • 2026年湖州代理记账推荐榜单:5家靠谱专业服务机构精选 - 本地品牌推荐
  • DeepSeek前端重构解析:Qwik架构、WebSocket连接池与Shiki代码高亮实战
  • Arduino避障机器人实战:从传感器原理到代码实现的完整指南
  • Codex周活破500万背后:AI编程工具的终局是什么?
  • 微博相册批量下载神器:告别繁琐手动保存,一键获取高清原图
  • 掌握咖啡烘焙艺术的3大核心:Artisan软件如何让数据驱动风味革命
  • 上海配电房电试公司怎么选?从资质到实战的全景判断 - 资讯纵览
  • 工业相机选型与镜头参数完全指南:从原理到落地的关键决策
  • 揭秘文本转图表工具的效率革命:如何用代码思维重塑可视化工作流
  • WiiM Bar 7 月发布:479 美元打破高音质高价魔咒,拓展全屋音频生态
  • 明日方舟素材库终极指南:免费获取完整游戏资源实战秘籍
  • 如何用Lano Visualizer为你的Windows桌面添加酷炫音乐可视化效果?
  • 3个技巧:用Draw.io Mermaid插件实现代码驱动图表设计
  • 破解窗户漏水反复修漏难题:‘测定施保’四阶根治法如何实现长效不漏? - 资讯纵览
  • 3分钟免费激活IDM完整版:终极下载体验解锁指南
  • UVa 383 Shipping Routes
  • 019、训练基础概念:Epoch Batch LearningRate Warmup EMA 的直观理解
  • 别再瞎试了!手把手教你用DC NXT的compile_ultra命令搞定物理综合(附完整脚本)
  • Java实现报价分级算法,上门回收预约+闲置商品上架全链路后端开发实战
  • 如何用智能视频分析工具将数小时视频压缩为5分钟可读报告
  • 年度必看!2026AI论文写作软件榜单(覆盖 99% 毕业论文需求)
  • 抖音批量下载终极指南:如何免费获取无水印高清视频
  • 计算机毕业设计之基于大数据的中医药传承平台的构建
  • 保姆级教程:在Ubuntu 22.04上编译COLMAP 3.9,附赠6个常见编译错误的解决方案
  • 2026年 北京烘焙培训推荐榜单:家庭私房/摆摊甜品/专业裱花奶油蛋糕与日式面包综合口碑优选 - 品牌企业推荐师(官方)
  • 高性价比广告标识工厂怎么选?2026 省钱选型实用指南 - GrowthUME
  • 开源IT资产管理系统Snipe-IT:如何三步解决企业资产管理难题
  • UltraStar Deluxe:从零开始打造你的开源卡拉OK娱乐中心
  • 高效下载抖音视频:douyin-downloader完整实用指南