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. Spring Boot项目中各配置文件的对比

    application.properties是Spring Boot的全局配置文件,放在src/main/resources目录下或者类路径的/config下,作用是对一些默认配置的配置值进行修改. ...

  2. iOS学习7:iOS沙盒(sandBox)机制(一)之获取沙盒路径及目录说明(转)

    转:http://my.oschina.net/joanfen/blog/151145 一.iOS沙盒机制 iOS的应用只能访问为该应用创建的区域,不可访问其他区域,应用的其他非代码文件都存在此目录下 ...

  3. JVM虚拟机内存溢出垃圾收集及类加载机制总结

    1.Java内存区域与内存溢出异常 虚拟机栈:为虚拟机执行Java方法服务 本地方法栈:为虚拟机使用到的native方法服务. Java堆:是Java虚拟机所管理的内存中最大的一块,被所有线程共享的一 ...

  4. ypeError: __init__() got an unexpected keyword argument 'shape'

    采用TensorFlow支持通过tf.Graph函数来生成新的向量图,代码如下: import tensorflow as tf g1 = tf.Graph() with g1.as_default( ...

  5. Prometheus 学习目录

    Prometheus 介绍 Prometheus 安装 https://www.bookstack.cn/read/prometheus-book/quickstart-why-monitor.md ...

  6. 16核锐龙9延期真正原因 A饭热情太恐怖了

    锐龙9 3950X处理器是AMD发布的首款16核游戏处理器,原本会在9月上市,上周末AMD官方宣布它会延期2个月上市,会在11月跟锐龙Threadripper三代处理器一起上市. 锐龙9 3950X的 ...

  7. YTT的提问以及由此引出的未来规划之思考

    未来规划之思考 我已经很久没有考虑过未来的规划了,之所以没有规划,是因为我觉得现实是复杂的,我现在的认知还不够深刻,建立在肤浅认知上的规划是容易经受现实的冲击而轻易改变的,与其规划变来变去,还不如干脆 ...

  8. Codeforces 1296E2. String Coloring (hard version)

    这道题和HDU1257一模一样,一开始窝都用贪心直接解,没法理解为什么求一个最长下降序列,直到看了巨巨的题解,先给出一个定理,Dilworth's theorem,离散学不好,补题两行泪,该定理是说, ...

  9. Day3-J-4 Values whose Sum is 0 POJ2785

    The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute ...

  10. 学习SpringBoot零碎记录——配置应用URL名称

    学习SpringBoot配置应用名称,结果发现坑 到网上找 到 https://blog.csdn.net/qq_40087415/article/details/82497668 server: p ...