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. Atcoder Beginning Contest 134E(二分查找(upper_bound),思维)

    #include<bits/stdc++.h>using namespace std;int a[100007],f[100007],ans,n;int main(){ cin>&g ...

  2. [NOI 2011]NOI 嘉年华

    Description 题库链接 给你 \(n\) 个区间,让你选出其中一些分为两组,要求两组区间不能有交集,组内可以有交集.让你最大化两组之间区间个数较小的那一组的选取区间个数.以及对于每个区间 \ ...

  3. Navigation源码(一) move_base最全解析

    一.概述 目测是全网最全的解析,花了几个小时通读并整理的,供大家参考学习. 概况的话可以看下古月居 https://www.guyuehome.com/270,其实它是翻译官方的,英语ok的可以去ro ...

  4. web前端面试第一次[addEventListenr();绑定事件]

    //当一个元素同时处理多个函数,这里使用按钮 //addEventListener(string类型,处理函数,boolean); <input type="button" ...

  5. Python 爬取 北京市政府首都之窗信件列表-[数据处理]

    日期:2020.01.24 博客期:132 星期五 [代码说明,如果要使用此页代码,必须在本博客页面评论区给予说明] //博客总体说明 1.准备工作 2.爬取工作 3.数据处理(本期博客) 4.信息展 ...

  6. nmap 速查命令

    进行ping扫描,打印出对扫描做出响应的主机,不做进一步测试(如端口扫描或者操作系统探测) nmap -sP 192.168.1.0/24 仅列出指定网络上的每台主机,不发送任何报文到目标主机 nam ...

  7. Xcode 9.0 报错,Safe Area Layout Guide Before IOS 9.0

    解决方案就是: 第一步 第二步 第三步 重新编译.

  8. 别再写getter,setter方法了,用Lombok来简化你的代码吧

    前言 在实际开发中,有些代码是重复的.IDE一键生成的,不写不行,写了又觉得代码太臃肿,不美观.如果你也有这种体会,那么,请使用Lombok插件吧,真的非常好用.Lombok的使用也非常简单,都是各种 ...

  9. JS实现深拷贝,浅拷贝的方法

    在 JS 中,函数和对象都是浅拷贝(地址引用):其他的,例如布尔值.数字等基础数据类型都是深拷贝(值引用). 深拷贝 JSON.parse(JSON.stringify(src)):这种方法有局限性, ...

  10. 3676: [Apio2014]回文串 求回文串长度与出现次数的最大值

    「BZOJ3676」[Apio2014] 回文串   Description 考虑一个只包含小写拉丁字母的字符串s.我们定义s的一个子串t的“出 现值”为t在s中的出现次数乘以t的长度.请你求出s的所 ...