Advertisement
jeff69

Untitled

Jul 20th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define sc(a) scanf("%d",&a)
  4. typedef long long ll;
  5. const int MX=1e5+69;
  6.  
  7. ll n,m,a,mod=1000000007;
  8.  
  9. struct mat
  10. {
  11.     ll a[2][2];
  12.  
  13. };
  14.  
  15. mat mul(mat x,mat y)
  16. {
  17.     mat z;
  18.     for(int i=0;i<2;i++)
  19.     {
  20.         for(int j=0;j<2;j++)
  21.         {
  22.             z.a[i][j]=0;
  23.             for(int k=0;k<2;k++)
  24.             {
  25.                 z.a[i][j]+=x.a[i][k]*y.a[k][j];
  26.                 z.a[i][j]=(z.a[i][j]%mod+mod)%mod;
  27.             }
  28.         }
  29.     }
  30.     return z;
  31. }
  32.  
  33.  
  34.  
  35. mat matpo(mat x, int po)
  36. {
  37.     if(po==1)return x;
  38.     if(po%2==0) return matpo(mul(x,x),po/2);
  39.     return mul(x,matpo(mul(x,x),po/2));
  40. }
  41.  
  42.  
  43. int main()
  44. {
  45.     int t;
  46.     cin>>t;
  47.     while(t--)
  48.     {
  49.         cin>>n>>m;
  50.         ll ans =0;
  51.         ll mm=1;
  52.         a=m;
  53.         while(a)
  54.         {
  55.             a/=10;
  56.             mm*=10;
  57.         }
  58.         /// HERE NIGGA
  59.         mm%=mod;
  60.         ///
  61.         mat x;
  62.         x.a[0][0]=mm+1;
  63.         x.a[0][1]=1;
  64.         x.a[1][0]=-mm;
  65.         x.a[1][1]=0;
  66.         int l=1;
  67.         if(n==1){cout<<m%mod<<endl;continue;}
  68.         mat z=matpo(x,n-1);
  69.         m%=mod;
  70.         ans=m*z.a[0][0];
  71.         ans=(ans%mod+mod)%mod;
  72.         cout<<ans<<endl;
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement