【题解】ABC460E

0

\(link\)

1:发现性质

发现 \(y\) 除了提供后加位数 \(l\) ,啥用也没

只考虑 \(k=x\)\(l\) 就可以了

2:推柿子

\(k=k \times (10^l)(modM)\)

\((10^l-1) \times k=0(mod M)\)

定义 \((10^l-1)=x\)

\(k \times x=0(mod M)\)

\(M|k \times x\)

定义 \(d=gcd(M,x)\)

\(\frac{M}{d}|k\)

\(\lfloor \frac{k}{M/d} \rfloor\) 即可

3:代码

// Problem: E - x + y ≡ x + y
// Contest: AtCoder - AtCoder Beginner Contest 460
// URL: https://atcoder.jp/contests/abc460/tasks/abc460_e
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define int unsigned long long 
#define Pair pair<int,int>
#define eps 1e-6
using namespace std;
using LL=long long;
const int N=5e5+10,P=998244353;
int num[20];
int tot(int x){
	int res=0;
	while(x){
		res++;
		x/=10;
	}
	return res;
}
int powl(int a,int b){
	int res=1;
	while(b--) res*=a;
	return res;
}
int gcd(int a,int b){
	return b==0?a:gcd(b,a%b);
}
void solve(){
	int n,m;cin>>n>>m;
	num[1]=9;
	int t=tot(n);
	for(int i=2;i<t;i++) num[i]=num[i-1]*10%P;
	
	num[t]=n-powl(10LL,t-1)+1;num[t]%=P;
	
	int ans=0;
	for(int i=1;i<=t;i++){
		int x=powl(10LL,i)-1;
		ans+=n/(m/gcd(m,x))%P*num[i]%P;
		ans%=P;
	}
	cout<<ans<<"\n";
	
}
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1;
	cin>>t;
	while(t--) solve();
	return 0;
}

4.反思

  • 最开始想到容斥了,卡了几十分钟,所以想到一个做法一定要先hack几组

  • 会越界,记得用ull

posted @ 2026-05-31 22:59  Aistyr  阅读(16)  评论(0)    收藏  举报