给定一个数输出它重复n遍的数

题目:http://codeforces.com/gym/101061/problem/G

题意:给定一个数输出它重复n遍的数

解答:因为数比较大而且需要模运算,所以可以根据等比数列求和的公式算出。要用到逆元。

#include
#include
#include
#include
#define ll long long
#define mod 1000000007
using namespace std;
ll qpow(ll a,ll n)
{
    ll r = 1;
    while(n)
    {
        if(n&1)
            r = (r*a) % mod;
        a = (a * a)%mod;
        n >>= 1;
    }
    return r;
}
int main()
{
    ll a,b;
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%lld%lld",&a,&b);
        ll num = 1;
        int len = 0;
        ll tmp = b;
        while(tmp)
        {
            tmp /= 10;
            num = num * 10;
        }
        num %= mod;
        ll t1 = qpow(num,a);
      //  cout << a << endl;
        t1 = (b * ((t1-1+mod)%mod))%mod;
        ll ans = t1 * (qpow((num-1+mod)%mod,mod-2)) % mod;
        printf("%lld\n",ans);
    }
    return 0;
}


你可能感兴趣的:(数学)