HDU 6395 2018 Multi-University Training Contest 7 (快速幂+分块)
Sequence
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 1186 Accepted Submission(s): 433
Your job is simple, for each task, you should output Fn module 109+7.
Then, for the next T lines, each line consists of 6 integers, A , B, C, D, P, n.
1≤T≤200≤A,B,C,D≤1091≤P,n≤109
3 3 2 1 3 5
3 2 2 2 1 4
24
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const int maxn=3e6+50;
const ll inf=0x3f3f3f3f3f3f;
ll a,b,c,d,p,n;
ll k,kk;
ll fun[100000005];
struct node{
ll a[3][3];
void init(){
memset(a,0,sizeof(a));
for(int i=0;i<3;i++){
a[i][i]=1;
}
}
};
node mul(node a,node b)
{
node ans;
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
ans.a[i][j]=0;
for(int k=0;k<3;k++){
ans.a[i][j]+=a.a[i][k]*b.a[k][j];
ans.a[i][j]%=mod;
}
}
}return ans;
}
void output(node a){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
cout<<a.a[i][j]<<" ";
}cout<<endl;
}
}
node qpow(node a,ll n){
node ans;
ans.init();
while(n){
if(n&1)ans=mul(ans,a);
a=mul(a,a);
n/=2;
}
return ans;
}
node ac;
void init(ll d,ll c,ll x){
ac.a[0][0]=d;ac.a[0][1]=c;ac.a[0][2]=x; /*ac D C P/I */
ac.a[1][0]=1;ac.a[1][1]=0;ac.a[1][2]=0; /* 1 0 0 */
ac.a[2][0]=0;ac.a[2][1]=0;ac.a[2][2]=1; /* 0 0 1 */
}
node anw;
void init2(ll a,ll b){
anw.a[0][0]=b;anw.a[1][0]=a;anw.a[2][0]=1; /*fn*/
} /*fn-1*/
node init3(node one,node two){ /*1*/
node retu;
retu.a[0][0]=(one.a[0][0]*two.a[0][0]+one.a[0][1]*two.a[1][0]+one.a[0][2]*two.a[2][0])%mod;
retu.a[1][0]=(one.a[1][0]*two.a[0][0]+one.a[1][1]*two.a[1][0]+one.a[1][2]*two.a[2][0])%mod;
retu.a[2][0]=(one.a[2][0]*two.a[0][0]+one.a[2][1]*two.a[1][0]+one.a[2][2]*two.a[2][0])%mod;
return retu;
} int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int t;
cin>>t;
while(t--){
cin>>a>>b>>c>>d>>p>>n;
k=p/n;kk=p%n;
if(n==1){cout<<a<<endl;continue;}
if(n==2){cout<<b<<endl;continue;}
else{
init(d,c,1);
init2(a,b);
//output(ac);
// output(anw);
for(ll i=3;i<=n;){
if(p/i==0){
ll num=n-i+1;
init(d,c,0);
node mid=qpow(ac,num);
anw=init3(mid,anw);
break;
}
else{
ll k=min(n,p/(p/i));//num表示p/i这个值最大到哪一个
ll num=k-i+1;
init(d,c,p/i);
node mid=qpow(ac,num);
anw=init3(mid,anw);
i=k+1;
}
} cout<<anw.a[0][0]<<endl;
}
}
return 0;
}
HDU 6395 2018 Multi-University Training Contest 7 (快速幂+分块)的更多相关文章
- hdu 4915 Parenthese sequence--2014 Multi-University Training Contest 5
主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4915 Parenthese sequence Time Limit: 2000/1000 MS (Ja ...
- hdu 4902 Nice boat--2014 Multi-University Training Contest 4
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=4902 Nice boat Time Limit: 30000/15000 MS (Java/Othe ...
- hdu 4925 Apple Tree--2014 Multi-University Training Contest 6
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others ...
- HDU校赛 | 2019 Multi-University Training Contest 6
2019 Multi-University Training Contest 6 http://acm.hdu.edu.cn/contests/contest_show.php?cid=853 100 ...
- HDU校赛 | 2019 Multi-University Training Contest 5
2019 Multi-University Training Contest 5 http://acm.hdu.edu.cn/contests/contest_show.php?cid=852 100 ...
- HDU校赛 | 2019 Multi-University Training Contest 4
2019 Multi-University Training Contest 4 http://acm.hdu.edu.cn/contests/contest_show.php?cid=851 100 ...
- HDU校赛 | 2019 Multi-University Training Contest 3
2019 Multi-University Training Contest 3 http://acm.hdu.edu.cn/contests/contest_show.php?cid=850 100 ...
- HDU校赛 | 2019 Multi-University Training Contest 2
2019 Multi-University Training Contest 2 http://acm.hdu.edu.cn/contests/contest_show.php?cid=849 100 ...
- HDU校赛 | 2019 Multi-University Training Contest 1
2019 Multi-University Training Contest 1 http://acm.hdu.edu.cn/contests/contest_show.php?cid=848 100 ...
随机推荐
- 《Cracking the Coding Interview》——第9章:递归和动态规划——题目7
2014-03-20 03:35 题目:实现画图的Flood Fill操作. 解法:DFS和BFS皆可,但BFS使用的队列在时间复杂度上常数项比较大,速度略慢,所以我选了DFS.当然,如果图很大的话D ...
- 去掉referer信息
<iframe src="auto-refresh.html" width=500 height=500 rel="noreferrer">< ...
- .Net导出Word和Excel
using System; using System.Collections.Generic; using System.Linq; using System.Web; public class Ex ...
- STL之算法使用简介
accumlate : iterator 对标志的序列中的元素之和,加到一个由 init 指定的初始值上.重载的版本不再做加法,而是传进来的二元操作符被应用到元素上. adjacent_differ ...
- node + express + iis + iisnode + urlrewrite搭建站点
前提条件:安装iis的电脑 准备条件: 1.下载iisnode 地址https://github.com/tjanczuk/iisnode/wiki/iisnode-releases 安装 2.下载 ...
- kvm竟然抓不到kvm的tracepoint
今天终于把kvm给搭起来了,打开了host机的tracepoint竟然一个都没有抓到,这是咋回事? 难道kvm的东西只有在启动的时候才会被抓到? 虚拟出来一块内存一块CPU,虚拟出来一个内存.感觉都好 ...
- file mmap
do_set_pmd 统计参数只会在这里设置: add_mm_counter(vma->vm_mm, MM_FILEPAGES, HPAGE_PMD_NR); 但是这貌似都是处理大页的情况哪,小 ...
- [ARC083F] Collecting Balls [建二分图+环套树定向+建拓扑图+树的拓扑序计数]
题面 [传送门](https://arc083.contest.atcoder.jp/tasks/arc083_d) 思路 这是一道真正的好题 第一步:转化模型 行列支配类的问题,常见做法就是把行和列 ...
- [codeforces] 359D Pair of Numbers
原题 RMQ st表棵题 要想让一个区间里的所有数都可以整除其中一个数,那么他一定是这个区间内的最小值,并且同时是这个区间的gcd.然后这个问题就转化成了RMQ问题. 维护两个st表,分别是最小值和g ...
- 在Linux内核中添加系统调用,并编译内核
1 环境准备 运行系统:vmware下安装的ubuntu10.10 32bit桌面版. 编译内核版本: linux-2.6.32.63 内核目录: /home/wanchouchou/linuxKer ...