G. Repeat it

time limit per test

2.0 s

memory limit per test

64 MB

input

standard input

output

standard output

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 Nseparated 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.

Example
input

Copy
3
4 31
8 1
123 123
output

Copy
31313131
11111111
388853804 题意:给定m和n,要求m个n数字形式拼接起来的值对1000000007取模

#include <iostream>
#include<string.h>
#include<stdio.h>
#define ll long long
using namespace std;
const ll mod = ;
ll n,t,k,temp,len;
struct mat//定义矩阵结构体
{
ll m[][];
mat()
{
memset(m, , sizeof(m));
}
};
mat mul(mat &A, mat &B)
{
mat C;
for (int i = ; i < ; i++)
{
for (int j = ; j < ; j++)
{
for (int k = ; k < ; k++)
{
C.m[i][j] = (C.m[i][j] + A.m[i][k] * B.m[k][j]) % mod;
}
}
}
return C;
}
mat pow(mat A, ll n)
{
mat B;
for(int i=;i<;i++)//初始化方阵
B.m[i][i]=; //初始被乘矩阵的初值
B.m[][]=k;
B.m[][]=; while (n)
{
if (n & )
B = mul(A, B);//注意这里,矩阵的左乘和右乘是不一样的,对应的系数矩阵也不一样
A = mul(A, A);
n >>= ;
}
return B;
}
int main()
{
cin>>t;
while (t--)
{
cin>>n>>k;
k=k%mod;
len=,temp=k;
while(temp)
{
temp=temp/;
len=len*;;
}
mat A;//矩阵A是系数矩阵(转移矩阵)
A.m[][]=len%mod;//记得对len取模,wa了无数次
A.m[][]=k;
A.m[][]=;
if(n==)
{
printf("%lld\n",k);
} else
{
mat B = pow(A, n-);
printf("%lld\n",B.m[][]%mod);
}
}
return ;
}

 

G. Repeat it的更多相关文章

  1. 从js的repeat方法谈js字符串与数组的扩展方法

    js将字符串重复N次的repeat方法的8个版本 /* *@desc: 将一个字符串重复自身N次 */ //版本1:利用空数组的join方法 function repeat(target, n) { ...

  2. How to install more voices to Windows Speech?

    !!!WARNING!!! This involves manual edits to your registry. If you mess it up, don't blame me. Do at ...

  3. MySQL Procedure(MySQL存储过程)[转]

    ------Creating Stored Procedures in MySQL------ --Make sure you have version 5 of MySQL:   SELECT VE ...

  4. Storyboards Tutorial 03

    这一节主要介绍segues,static table view cells 和 Add Player screen 以及 a game picker screen. Introducing Segue ...

  5. 文件图标SVG

    ​<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink ...

  6. MySQL-procedure(loop,repeat)

    在 MySQL-procedure(cursor,loop) 中将spam_keyword表中的文字全部分割到t表当中,且每一行的字都不重复,那t表可以用来当作一个小字典,只有1000来个字符,这次把 ...

  7. Moto G如何进入开发者选项

    最近买了个Moto G做应用开发,突然发现开发者选项居然没有,搜索了一下发现是Google隐藏了此选项. http://allaboutmotog.com/moto-g-how-to-guide/ac ...

  8. .ascx.g.cs文件不能生成 The name ‘InitializeControl’ does not exist in the current context - Visual Web part Sharepoint

    InitializeControl doesn't exsit When using visual studio 2012 for developing SharePoint 2013 Visual ...

  9. LINQ标准查询操作符(三)——Aggregate、Average、Distinct、Except、Intersect、Union、Empty、DefaultIfEmpty、Range、Repeat

    七.聚合操作符 聚合函数将在序列上执行特定的计算,并返回单个值,如计算给定序列平均值.最大值等.共有7种LINQ聚合查询操作符:Aggregate.Average.Count.LongCount.Ma ...

随机推荐

  1. windows下代码规范检测工具sonarqube安装与使用,含与maven的结合

    一.首先下载sonarqube   地址 : https://www.sonarqube.org/downloads/   (最新版本支持java11+,博主下载支持java8的版本7.7), 下载S ...

  2. Linux 长时间操作设置不断开

    1.第一次尝试失败 修改/etc/ssh/sshd_config文件, 找到 ClientAliveInterval 0 ClientAliveCountMax 3 并将注释符号("#&qu ...

  3. 安装哪个python版本比较好

    四.电脑是32位选择第一个,64为选择第二个

  4. ng-repeat 设定select 选择项

    <select class="form-control m-b" name="FPermissionID" ng-model="mgfunc.F ...

  5. Py西游攻关之基础数据类型(五)-集合

    Py西游攻关之基础数据类型 - Yuan先生 https://www.cnblogs.com/yuanchenqi/articles/5782764.html 八 集合(set) 集合是一个无序的,不 ...

  6. python神器-pycharm安装与使用(全网最新)

      pycharm分为社区版(免费)和专业版(收费/破解),以下安装仅适用于社区版 下载方式1: 官网下载:https://www.jetbrains.com/pycharm/download/dow ...

  7. 5款微信小程序开发工具使用报告,微信官方开发工具还有待提升

    微信小程序已经内测有一段时间了,笔者本着好奇加学习的心态写了几个小demo,虽然在MINA框架上并没有遇到太多的坑,但官方开发工具实在不敢恭维. api提示不全,要一个个查api啊,写代码超级慢啊 很 ...

  8. 【快学springboot】6.WebMvcConfigurer配置静态资源和解决跨域

    勘误 有个朋友说:为什么我配置了WebMvcConfigurer,静态资源static依然能访问?! 这里是本人的失误,我在启动类中添加了EnableWebMvc注解(文章里却没有提及,最好的做法是放 ...

  9. pycharm安装报错Non-zero exit co?

    pycharm安装第三方库时报错Non-zero exit co? 原因:版本找不到 解决思路: 1.用pip install pandas报错,尝试用python -m pip install -- ...

  10. Py2与Py3的区别

    总结Py2 与Py3 的区别 1 编码区别 在Python2中有两种字符串类型str和Unicode. 默认ASCII python2 str类型,相当于python3中的bytes类型 python ...