HDU多校Round 7
Solved:2
rank:293
J. Sequense
不知道自己写的什么东西 以后整数分块直接用 n / (n / i)表示一个块内相同n / i的最大i
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const ll mod = 1e9 + ;
- ll A, B, C, D, P, n;
- struct martix
- {
- ll c[][];
- };
- martix mul(martix A, martix B)
- {
- martix res;
- memset(res.c, , sizeof(res.c));
- for(int i = ; i < ; i++)
- for(int j = ; j < ; j++)
- for(int k = ; k < ; k++)
- res.c[i][j] = (res.c[i][j] + A.c[i][k] * B.c[k][j] % mod) % mod, (res.c[i][j] += mod) %= mod;
- return res;
- }
- martix pow_mod(martix x, ll y)
- {
- martix res;
- memset(res.c, , sizeof(res.c));
- res.c[][] = res.c[][] = res.c[][] = 1LL;
- while(y)
- {
- if(y & ) res = mul(res, x);
- x = mul(x, x);
- y >>= ;
- }
- return res;
- }
- int main()
- {
- martix og;
- int T;
- scanf("%d", &T);
- while(T--)
- {
- scanf("%lld%lld%lld%lld%lld%lld", &A, &B, &C, &D, &P, &n);
- memset(og.c, , sizeof(og.c));
- og.c[][] = D + ;
- og.c[][] = C - D;
- og.c[][] = -C;
- og.c[][] = og.c[][] = ;
- ll f1 = A;
- ll f2 = B;
- if(n == )
- {
- printf("%lld\n", A);
- continue;
- }
- if(n == )
- {
- printf("%lld\n", B);
- continue;
- }
- if(n <= )
- {
- for(int i = ; i <= n; i++)
- {
- ll tmp = f1 * C % mod + D * f2 % mod + P / i;
- tmp %= mod;
- f1 = f2;
- f2 = tmp;
- }
- printf("%lld\n", f2);
- continue;
- }
- for(int i = ; i <= ; i++)
- {
- ll tmp = f1 * C % mod + D * f2 % mod + P / i;
- tmp %= mod;
- f1 = f2;
- f2 = tmp;
- }
- ll now = ;
- ll f3 = C * f1 % mod + D * f2 % mod + P / now; f3 %= mod;
- //cout<<f3<<endl;
- ll ans = f3;
- while(now < n)
- {
- if(P / now == P / n)
- {
- ans = ;
- martix tmp1 = pow_mod(og, n - now);
- ans = tmp1.c[][] * f3 % mod + tmp1.c[][] * f2 % mod; ans %= mod;
- ans += tmp1.c[][] * f1 % mod; ans %= mod;
- ans += mod; ans %= mod;
- break;
- }
- if(now + >= n)
- {
- for(int i = now + ; i <= n; i++)
- {
- ll ttmp = f2 * C % mod + D * f3 % mod + P / i;
- ttmp %= mod;
- f1 = f2;
- f2 = f3;
- f3 = ttmp;
- }
- ans = f3;
- break;
- }
- if(P / (now + ) != P / now)
- {
- for(int i = now + ; i <= now + ; i++)
- {
- ll tymp = f2 * C % mod + D * f3 % mod + P / i;
- tymp %= mod;
- f1 = f2;
- f2 = f3;
- f3 = tymp;
- }
- now += ;
- continue;
- }
- ll l = now, r = n;
- ll mid = l + r >> ;
- while(l + < r)
- {
- mid = l + r >> ;
- if(P / mid == P / now) l = mid;
- else r = mid;
- }
- ll opp;
- if(P / r == P / now) opp = r;
- else opp = l;
- if(opp - now >= )
- {
- martix tmp2 = pow_mod(og, opp - now - );
- ll tt = ;
- tt = tmp2.c[][] * f3 % mod + tmp2.c[][] * f2 % mod; tt %= mod;
- tt += tmp2.c[][] * f1 % mod; tt %= mod;
- tt += mod; tt %= mod;
- tmp2 = mul(tmp2, og);
- ll ttt = ;
- ttt = tmp2.c[][] * f3 % mod + tmp2.c[][] * f2 % mod; ttt %= mod;
- ttt += tmp2.c[][] * f1 % mod; ttt %= mod;
- ttt += mod; ttt %= mod;
- f1 = tt;
- f2 = ttt;
- f3 = C * f1 % mod + D * f2 % mod + P / opp;
- f3 %= mod;
- now = opp;
- }
- else
- {
- for(int i = now + ; i <= opp; i++)
- {
- ll tmpp = C * f2 % mod + D * f3 % mod + P / i;
- tmpp %= mod;
- f1 = f2;
- f2 = f3;
- f3 = tmpp;
- }
- now = opp;
- }
- }
- printf("%lld\n", ans);
- }
- return ;
- }
HDU多校Round 7的更多相关文章
- HDU多校Round 8
Solved:2 rank:141 D. Parentheses Matrix n,m有一个小于6的时候是一种构造方法 答案是n + (m - 2) / 2 (n > m) 都大于6的时候 可以 ...
- HDU多校Round 6
Solved:2 rank:452 I. Werewolf 没有铁人 找铁狼 如果一个环中只有一条狼人边那个人就是铁狼 说铁狼是好人的人也是铁狼 #include <bits/stdc++.h& ...
- HDU多校Round 5
Solved:3 rank:71 E. Everything Has Changed #include <bits/stdc++.h> using namespace std; const ...
- HDU多校Round 4
Solved:3 rank:405................................. B. Harvest of Apples 知道了S(n,m) 可以o(1)的求S(n - 1, m ...
- HDU多校Round 3
Solved:4 rank:268 C. Dynamic Graph Matching 状压DP一下 #include <stdio.h> #include <algorithm& ...
- HDU多校Round 1
Solved:5 rank:172 A.Maximum Multiple #include <stdio.h> #include <algorithm> #include &l ...
- hdu 5667 BestCoder Round #80 矩阵快速幂
Sequence Accepts: 59 Submissions: 650 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536 ...
- hdu 5643 BestCoder Round #75
King's Game Accepts: 249 Submissions: 671 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 6 ...
- hdu 5641 BestCoder Round #75
King's Phone Accepts: 310 Submissions: 2980 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
随机推荐
- 嵌入式开发之davinci--- 8127 和8148的区别
1.主要的差别是8148有sata接口,8127没有 2.经过最近各方查找,应该是8107中把DSP砍掉了,8127如1楼所示 http://www.deyisupport.com/question_ ...
- mongodb配置主从模式
Mongodb的replication主要有两种:主从和副本集(replica set).主从的原理和mysql类似,主节点记录在其上的所有操作oplog,从节点定期轮询主节点获取这些操作,然后对自己 ...
- where 1=1影响效率以及having和where的区别
低效的“WHERE 1=1” 网上有不少人提出过类似的问题:“看到有人写了WHERE 1=1这样的SQL,到底是什么意 思?”. 其实使用这种用法的开发人员一般都是在使用动态组装的SQL. 让我们想像 ...
- bzoj1898 [Zjoi2005]Swamp 沼泽鳄鱼——矩阵快速幂
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1898 求到达方案数...还是矩阵快速幂: 能够到达就把邻接矩阵那里赋成1,有鳄鱼的地方从各处 ...
- Probabilistic interpretation
Under the previous probabilistic assumptions on the data, least-squares regression corresponds to fi ...
- UEditor动态添加图片访问路径前缀
在使用UEditor上传图片时发现上传图片后在编辑器中不能显示上传的图片,在这里是需要在jsp/config.json中设置图片访问路径前缀,即项目的根路径,在config.json只能填写字符串的配 ...
- sql的where条件中包含中文,查询不出来的处理方法
SELECT * FROM phonenumber_info where PROVANCE=N'广东' and CITY=N'中山市'
- bzoj 3942: [Usaco2015 Feb]Censoring【kmp+栈】
好久没写kmp都不会写了-- 开两个栈,s存当前串,c存匹配位置 用t串在栈s上匹配,栈每次入栈一个原串字符,用t串匹配一下,如果栈s末尾匹配了t则弹栈 #include<iostream> ...
- bzoj 1629: [Usaco2007 Demo]Cow Acrobats【贪心+排序】
仿佛学到了贪心的新姿势-- 考虑相邻两头牛,交换它们对其他牛不产生影响,所以如果交换这两头牛能使这两头牛之间的最大值变小,则交换 #include<iostream> #include&l ...
- Akka源码分析-Cluster-Distributed Publish Subscribe in Cluster
在ClusterClient源码分析中,我们知道,他是依托于“Distributed Publish Subscribe in Cluster”来实现消息的转发的,那本文就来分析一下Pub/Sub是如 ...