GYM 101061G


传送门:GYM 101061G


G. Repeat it
time limit per test2.0 s memory limit per test64 MB inputstandard input outputstandard output

Problem Description
Jad has bought a new computer, a really weird computer!!
Every time he copies some number from the screen and pastes it, the computer pastes it many times instead of once!
Jad tested his computer many times, and now he knows how many times the computer will paste each copied number.
For example, In case the new computer repeated each copied number 4 times. When Jad copies the number 31 and pastes it, the number that appears on the screen would be 31313131.
Given N the number that Jad copied, and M the number of times the new computer is pasting each copied number. you have to print the number that will appear on the screen.
Since the number might be very big, you are asked to print it modulo 1000000007.

Input
The first line of the input consists of a single integer t, the number of test cases. Each test case consists of two numbers M and N separated by a single space:
(1 ≤ M ≤ 109) is the number of times the new computer pasted the number N.
(0 ≤ N ≤ 109) is the number Jad had copied.

Output
For each test case print one line, the number that will appear on the screen modulo 1000000007.

Sample Input
3
4 31
8 1
123 123

Sample Output
31313131
11111111
388853804




题意:
就是将n复制m次,然后得出来的数mod1e9+7;


题解:
这题打比赛的时候卡了好久,当时想的是用大数取模做,可惜我不会= _ = ,比完了之后问一个大佬怎么做来着,才知道可以转化成等比数列求和,对分母取逆元即可。菜的真实

比如说 4 31
那么它的复制应该是这样一个过程:31+3100+310000+31000000
对于上面的过程,就是一个公比为100,首项为31的等比数列求和;
由此可得复制的公比就要看要复制的数有多少位,假设有w位,那么公比就是10w

等比数列求和:Sn= n ∗ ( q m − 1 ) q − 1 \frac{n*(q^m-1)}{q-1} q1n(qm1)



这里比较好奇的就是为什么我先把q算出来再求和,交上去就是WA,希望有大佬能告诉我原因。



AC代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const ll mod=1e9+7;
int t;
ll m,n;
ll quickpow(ll a,ll n)
{
  ll res=1;
  while(n)
  {
    if(n&1)
    {
      res=res*a;
      res%=mod;
    }
    a=a*a;
    a%=mod;
    n>>=1;
  }
  return res;
}
int fw(ll x)
{
  if(x/1000000000) return 10;
  if(x/100000000) return 9;
  if(x/10000000) return 8;
  if(x/1000000) return 7;
  if(x/100000) return 6;
  if(x/10000) return 5;
  if(x/1000) return 4;
  if(x/100) return 3;
  if(x/10) return 2;
  return 1;
}
int main()
{
  scanf("%d",&t);
  while(t--)
  {
    scanf("%I64d%I64d",&m,&n);
    int w=fw(n);
    //好奇为什么我这样做就是错的
    //ll base=1;
    //for(int i=1;i<=w;i++) base*=10;
    //ll temp=quickpow(base,m);
    ll temp=quickpow(10,m*w);
    ll fz=n*(temp-1)%mod;
    ll base=quickpow(10,w);
    ll fm=quickpow(base-1,mod-2);
    printf("%I64d\n",fm*fz%mod);
  }
  return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值