题意:求 $\sum_{i = 1} ^ n 10 ^ {i - 1} \bmod p$
做法: 不难得出 $\operatorname{ans} = \frac{10 ^ n - 1}{9} \bmod p$
用快速幂求即可。注意爆long long
#include<iostream>#define int long longusingnamespacestd;inlineintksc(inta,intb,constint&p){return(a*b-(int)((longdouble)(a)/p*b)*p+p)%p;}inlineintksm(inta,intb,constint&p){intc=1;for(a%=p;b;a=ksc(a,a,p),b>>=1)if(b&1)c=ksc(c,a,p);returnc;}voidsolve(){intn,p;cin>>n>>p;cout<<(ksm(10,n,9*p)-1+9*p)/9%p<<'\n';}signedmain(){cin.tie(0)->sync_with_stdio(0);int_;for(cin>>_;_--;)solve();return0;}
题意:求 $\sum_{i = 1} ^ n 10 ^ {i - 1} \bmod p$
做法: 不难得出 $\operatorname{ans} = \frac{10 ^ n - 1}{9} \bmod p$
用快速幂求即可。注意爆
long long