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 ...
随机推荐
- kafka 日志策略
日志查看: usr/local/kafka/kafka_2.11-2.4.0/bin/kafka-run-class.sh kafka.tools.DumpLogSegments --files /t ...
- Linux centosVMware Apache 配置防盗链、访问控制Directory、访问控制FilesMatch
一.配置防盗链 通过限制referer来实现防盗链的功能 配置文件增加如下内容 vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf //改为如下 ...
- FFmpeg RTSP流通过UDP传输问题
我自己在使用SRS服务的Ingest功能时发现在读取一个网络摄像头的RTSP流时一直不成功, 具体分析后发现SRS在调用FFmpeg时出了问题: /usr/local/ffmpeg/bin/ffmpe ...
- Windows密码安全性测试
一.本地管理员密码如何直接提取 1.1直接通过mimikatz读取管理员密码 (不能交互式,不能在webshell下用,图形化界面很好用) 第一条:privilege::debug ...
- 「luogu1613」跑路
传送门 Luogu 解题思路 对于所有可以用 \(2^k\) 形式表示的 \(dis(i,j)\),将\(i,j\)之间的 \(dis\) 置为 \(1\),可以用倍增 \(\text{Floyd}\ ...
- centos7搭建svn服务器及客户端设置
centos7搭建svn服务器及客户端设置 centos7貌似预装了svn服务(有待确认),因此我们直接启动该服务即可 一.svn服务端配置(服务器IP假设为192.168.100.1) 步骤1:创建 ...
- python组合数据类型和数据结构
//2019.12-071.pyhton里面组合数据类型主要有三种:集合(set).序列(字符串str.列表list and 元组tuple)和映射(字典dic)2.集合类型一般使用大括号{}来进行表 ...
- jwt 认证
目录 jwt 认证示意图 jwt 认证算法:签发与检验 drf 项目的 jwt 认证开发流程(重点) drf-jwt 框架基本使用 token 刷新机制(了解) jwt 认证示意图 jwt 优势 1 ...
- Manthan, Codefest 19(Div. 1 + Div. 2)
传送门 A. XORinacci 签到. Code /* * Author: heyuhhh * Created Time: 2020/2/26 9:26:33 */ #include <ios ...
- 第1节 storm编程:8、storm的分发策略
8. Storm的分发策略 Storm当中的分组策略,一共有八种: 所谓的grouping策略就是在Spout与Bolt.Bolt与Bolt之间传递Tuple的方式.总共有八种方式: 1)shuffl ...