G. Repeat it
G. Repeat it
2.0 s
64 MB
standard input
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.
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.
For each test case print one line, the number that will appear on the screen modulo 1000000007.
3
4 31
8 1
123 123
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的更多相关文章
- 从js的repeat方法谈js字符串与数组的扩展方法
js将字符串重复N次的repeat方法的8个版本 /* *@desc: 将一个字符串重复自身N次 */ //版本1:利用空数组的join方法 function repeat(target, n) { ...
- 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 ...
- MySQL Procedure(MySQL存储过程)[转]
------Creating Stored Procedures in MySQL------ --Make sure you have version 5 of MySQL: SELECT VE ...
- Storyboards Tutorial 03
这一节主要介绍segues,static table view cells 和 Add Player screen 以及 a game picker screen. Introducing Segue ...
- 文件图标SVG
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink ...
- MySQL-procedure(loop,repeat)
在 MySQL-procedure(cursor,loop) 中将spam_keyword表中的文字全部分割到t表当中,且每一行的字都不重复,那t表可以用来当作一个小字典,只有1000来个字符,这次把 ...
- Moto G如何进入开发者选项
最近买了个Moto G做应用开发,突然发现开发者选项居然没有,搜索了一下发现是Google隐藏了此选项. http://allaboutmotog.com/moto-g-how-to-guide/ac ...
- .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 ...
- LINQ标准查询操作符(三)——Aggregate、Average、Distinct、Except、Intersect、Union、Empty、DefaultIfEmpty、Range、Repeat
七.聚合操作符 聚合函数将在序列上执行特定的计算,并返回单个值,如计算给定序列平均值.最大值等.共有7种LINQ聚合查询操作符:Aggregate.Average.Count.LongCount.Ma ...
随机推荐
- java后端开发echarts
参考: https://blog.csdn.net/mxdmojingqing/article/details/77340245 https://github.com/abel533/ECharts
- 查看mysql进程
show processlist; show full processlist;
- IIS 应用程序池回收(代码实现)
回收 public void StartStopRecycleApp(string appName = "项目DLL名称", string method = "Recyc ...
- 「APIO2012」派遣
「APIO2012」派遣 传送门 当预算超过限制时,优先丢掉薪水高的忍者(左偏树维护一下),然后答案取合法答案的最大值. 参考代码: #include <algorithm> #inclu ...
- 科软-信息安全实验3-Rootkit劫持系统调用
目录 一 前言 二 Talk is cheap, show me the code 三 前期准备 四 效果演示 五 遇到的问题&解决 六 18.04的坑 七 参考资料 八 老师可能的提问 一 ...
- 无需密码攻击 Microsoft SQL Server
最近的一次渗透测试里,在我们捕获的一些数据包中发现了一些未经加密的 Microsoft SQL Server(MSSQL) 流量.起初,我们认为这样就可以直接嗅探到认证凭证,然而,MSSQL 加密了认 ...
- 【剑指Offer面试编程题】题目1386:旋转数组的最小数字--九度OJ
题目描述: 把一个数组最开始的若干个元素搬到数组的末尾,我们称之为数组的旋转.输入一个递增排序的数组的一个旋转,输出旋转数组的最小元素.例如数组{3,4,5,1,2}为{1,2,3,4,5}的一个旋转 ...
- DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnection method call to the connection manager "XXX" failed with error code 0xC0209303.
问题: 今天写了一个新的SSIS的ETL包,运行报如下错误. DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER. The AcquireConnec ...
- 本地虚拟机搭建ES集群
一.环境说明 1.物理机信息(主要): 内存:8G 系统/主频:Win7(旗舰版)64位/3.70GHZ 2.虚拟机信息: VMware Workstation 14 Pro 下载地址: 链接:htt ...
- CTU Open Contest 2019 AB题
小菜鸡飘过 A: Beer Barrels 题意:给出四个整数:A,B,K,C,:A,B,C都是大于0的个位数,问在所有仅有A或者B组成的K位数中,数字C的个数是多少 思路: 1.先考虑特殊情况: ( ...