Vjudge 中文题面传送门
解题思路
题目要求 ,这里不能先模上10007再去除以M,那么我们可以转变一下求值的方法:N%(M*10007)/M%10007 。
那么剩下最关键的就是怎么求N值了。
初始令 N=0 ,然后每次加 个 ,相当于做 次 N=N * 10+
但是题目中 ,直接暴力模拟肯定会 TLE ,所以我们可以借鉴一下矩阵快速幂的思想,具体看代码。
下次我们换一个不同的C继续做这个操作
假设第一次 ,
第二次 。
那么两次叠加 。
我们可以得到 第一个参数 ,第二个参数 。
这里使用类似矩阵快速幂的方法快速计算 次乘法。
AC code
#include<bits/stdc++.h>
#define ull unsigned long long
#define int long long//如果涉及到取模操作最好开个long long
using namespace std;
int n,m;
int mod;
int ans;
struct node{
int x;
int y;
node friend operator*(const node p,const node q){
return {p.x*q.x%mod,(p.y*q.x%mod+q.y)%mod};
}//重载运算符 *
};
node pows(node x,int y){
node tot={1,0};
while(y){
if(y&1) tot=tot*x;
x=x*x;
y>>=1;
}
return tot;
}//“快速幂”
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL),cout.tie(NULL);
cin>>n>>m;
mod=m*10007;
for(int i=1;i<=n;i++){
int x,y;
node k;
cin>>x>>y;
k=pows({10,x},y);
ans=(ans*k.x%mod+k.y)%mod;
}
ans=ans/m%mod;//最后这步别忘了
cout<<ans;
return 0;
}本蒟蒻没有还过审的题解,管理大大求过