Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- /*
- WAY 2 C_M:: M_F
- */
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- typedef short sh;
- const ld pi=acos(-1);
- const ld eps =1e-7;
- const int MX=1e5+3;
- ll gcdExtended(ll a, ll b, ll *x, ll *y);
- // Function to find modulo inverse of a
- ll modInverse(ll a, ll m)
- {
- ll x, y;
- ll g = gcdExtended(a, m, &x, &y);
- if (g != 1);
- //cout << 0<<endl;
- else
- {
- // m is added to handle negative x
- ll res = (x%m + m) % m;
- return res;
- }
- }
- // C function for extended Euclidean Algorithm
- ll gcdExtended(ll a, ll b, ll *x, ll *y)
- {
- // Base Case
- if (a == 0)
- {
- *x = 0, *y = 1;
- return b;
- }
- ll x1, y1; // To store results of recursive call
- ll gcd = gcdExtended(b%a, a, &x1, &y1);
- // Update x and y using results of recursive
- // call
- *x = y1 - (b/a) * x1;
- *y = x1;
- return gcd;
- }
- const int MD=1e9+7;
- int p;
- ll M(int x)
- {
- if(x==0)return 1;
- ll ans;
- ans=M(x/2)%MD;
- ans*=ans;
- ans%=MD;
- if(x%2)ans*=p;
- ans%=MD;
- return ans ;
- }
- int main()
- {
- int t;
- cin>>t;
- while(t--){
- int x,n,z;
- cin>>n>>z;
- if(n==0)
- {
- cout<<0<<endl;
- continue;
- }
- x=1;
- int temp=z;
- while(temp)
- {
- temp/=10;
- x*=10;
- }
- //cout<<x<<endl;
- ll a = x-1, m = 1e9+7;
- ll b=modInverse(a, m);
- //cout<<b<< ' ';
- p=x;
- ll s=M(n);
- s--;
- s+=MD;
- s%=MD;
- // cout<<s<<endl;
- s*=b;
- s%=MD;
- s*=z;
- s%=MD;
- cout<<s<<endl;}
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement