Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define sc(a) scanf("%d",&a)
- typedef long long ll;
- const int MX=1e5+69;
- ll n,m,a,mod=1000000007;
- struct mat
- {
- ll a[2][2];
- };
- mat mul(mat x,mat y)
- {
- mat z;
- for(int i=0;i<2;i++)
- {
- for(int j=0;j<2;j++)
- {
- z.a[i][j]=0;
- for(int k=0;k<2;k++)
- {
- z.a[i][j]+=x.a[i][k]*y.a[k][j];
- z.a[i][j]=(z.a[i][j]%mod+mod)%mod;
- }
- }
- }
- return z;
- }
- mat matpo(mat x, int po)
- {
- if(po==1)return x;
- if(po%2==0) return matpo(mul(x,x),po/2);
- return mul(x,matpo(mul(x,x),po/2));
- }
- int main()
- {
- int t;
- cin>>t;
- while(t--)
- {
- cin>>n>>m;
- ll ans =0;
- ll mm=1;
- a=m;
- while(a)
- {
- a/=10;
- mm*=10;
- }
- /// HERE NIGGA
- mm%=mod;
- ///
- mat x;
- x.a[0][0]=mm+1;
- x.a[0][1]=1;
- x.a[1][0]=-mm;
- x.a[1][1]=0;
- int l=1;
- if(n==1){cout<<m%mod<<endl;continue;}
- mat z=matpo(x,n-1);
- m%=mod;
- ans=m*z.a[0][0];
- ans=(ans%mod+mod)%mod;
- cout<<ans<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement