Solved:2

rank:293

J. Sequense

不知道自己写的什么东西 以后整数分块直接用 n / (n / i)表示一个块内相同n / i的最大i

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll mod = 1e9 + ;
  5. ll A, B, C, D, P, n;
  6.  
  7. struct martix
  8. {
  9. ll c[][];
  10. };
  11.  
  12. martix mul(martix A, martix B)
  13. {
  14. martix res;
  15. memset(res.c, , sizeof(res.c));
  16. for(int i = ; i < ; i++)
  17. for(int j = ; j < ; j++)
  18. for(int k = ; k < ; k++)
  19. res.c[i][j] = (res.c[i][j] + A.c[i][k] * B.c[k][j] % mod) % mod, (res.c[i][j] += mod) %= mod;
  20. return res;
  21. }
  22.  
  23. martix pow_mod(martix x, ll y)
  24. {
  25. martix res;
  26. memset(res.c, , sizeof(res.c));
  27. res.c[][] = res.c[][] = res.c[][] = 1LL;
  28. while(y)
  29. {
  30. if(y & ) res = mul(res, x);
  31. x = mul(x, x);
  32. y >>= ;
  33. }
  34. return res;
  35. }
  36.  
  37. int main()
  38. {
  39. martix og;
  40.  
  41. int T;
  42. scanf("%d", &T);
  43. while(T--)
  44. {
  45. scanf("%lld%lld%lld%lld%lld%lld", &A, &B, &C, &D, &P, &n);
  46. memset(og.c, , sizeof(og.c));
  47. og.c[][] = D + ;
  48. og.c[][] = C - D;
  49. og.c[][] = -C;
  50. og.c[][] = og.c[][] = ;
  51.  
  52. ll f1 = A;
  53. ll f2 = B;
  54. if(n == )
  55. {
  56. printf("%lld\n", A);
  57. continue;
  58. }
  59. if(n == )
  60. {
  61. printf("%lld\n", B);
  62. continue;
  63. }
  64.  
  65. if(n <= )
  66. {
  67. for(int i = ; i <= n; i++)
  68. {
  69. ll tmp = f1 * C % mod + D * f2 % mod + P / i;
  70. tmp %= mod;
  71. f1 = f2;
  72. f2 = tmp;
  73. }
  74. printf("%lld\n", f2);
  75. continue;
  76. }
  77.  
  78. for(int i = ; i <= ; i++)
  79. {
  80. ll tmp = f1 * C % mod + D * f2 % mod + P / i;
  81. tmp %= mod;
  82. f1 = f2;
  83. f2 = tmp;
  84. }
  85.  
  86. ll now = ;
  87. ll f3 = C * f1 % mod + D * f2 % mod + P / now; f3 %= mod;
  88. //cout<<f3<<endl;
  89. ll ans = f3;
  90. while(now < n)
  91. {
  92. if(P / now == P / n)
  93. {
  94. ans = ;
  95. martix tmp1 = pow_mod(og, n - now);
  96. ans = tmp1.c[][] * f3 % mod + tmp1.c[][] * f2 % mod; ans %= mod;
  97. ans += tmp1.c[][] * f1 % mod; ans %= mod;
  98. ans += mod; ans %= mod;
  99. break;
  100. }
  101.  
  102. if(now + >= n)
  103. {
  104. for(int i = now + ; i <= n; i++)
  105. {
  106. ll ttmp = f2 * C % mod + D * f3 % mod + P / i;
  107. ttmp %= mod;
  108. f1 = f2;
  109. f2 = f3;
  110. f3 = ttmp;
  111. }
  112. ans = f3;
  113. break;
  114. }
  115.  
  116. if(P / (now + ) != P / now)
  117. {
  118. for(int i = now + ; i <= now + ; i++)
  119. {
  120. ll tymp = f2 * C % mod + D * f3 % mod + P / i;
  121. tymp %= mod;
  122. f1 = f2;
  123. f2 = f3;
  124. f3 = tymp;
  125. }
  126. now += ;
  127. continue;
  128. }
  129.  
  130. ll l = now, r = n;
  131. ll mid = l + r >> ;
  132. while(l + < r)
  133. {
  134. mid = l + r >> ;
  135. if(P / mid == P / now) l = mid;
  136. else r = mid;
  137. }
  138.  
  139. ll opp;
  140. if(P / r == P / now) opp = r;
  141. else opp = l;
  142.  
  143. if(opp - now >= )
  144. {
  145. martix tmp2 = pow_mod(og, opp - now - );
  146. ll tt = ;
  147. tt = tmp2.c[][] * f3 % mod + tmp2.c[][] * f2 % mod; tt %= mod;
  148. tt += tmp2.c[][] * f1 % mod; tt %= mod;
  149. tt += mod; tt %= mod;
  150.  
  151. tmp2 = mul(tmp2, og);
  152. ll ttt = ;
  153. ttt = tmp2.c[][] * f3 % mod + tmp2.c[][] * f2 % mod; ttt %= mod;
  154. ttt += tmp2.c[][] * f1 % mod; ttt %= mod;
  155. ttt += mod; ttt %= mod;
  156.  
  157. f1 = tt;
  158. f2 = ttt;
  159. f3 = C * f1 % mod + D * f2 % mod + P / opp;
  160. f3 %= mod;
  161. now = opp;
  162. }
  163. else
  164. {
  165. for(int i = now + ; i <= opp; i++)
  166. {
  167. ll tmpp = C * f2 % mod + D * f3 % mod + P / i;
  168. tmpp %= mod;
  169. f1 = f2;
  170. f2 = f3;
  171. f3 = tmpp;
  172. }
  173. now = opp;
  174. }
  175. }
  176. printf("%lld\n", ans);
  177. }
  178. return ;
  179. }

HDU多校Round 7的更多相关文章

  1. HDU多校Round 8

    Solved:2 rank:141 D. Parentheses Matrix n,m有一个小于6的时候是一种构造方法 答案是n + (m - 2) / 2 (n > m) 都大于6的时候 可以 ...

  2. HDU多校Round 6

    Solved:2 rank:452 I. Werewolf 没有铁人 找铁狼 如果一个环中只有一条狼人边那个人就是铁狼 说铁狼是好人的人也是铁狼 #include <bits/stdc++.h& ...

  3. HDU多校Round 5

    Solved:3 rank:71 E. Everything Has Changed #include <bits/stdc++.h> using namespace std; const ...

  4. HDU多校Round 4

    Solved:3 rank:405................................. B. Harvest of Apples 知道了S(n,m) 可以o(1)的求S(n - 1, m ...

  5. HDU多校Round 3

    Solved:4 rank:268 C. Dynamic Graph Matching  状压DP一下 #include <stdio.h> #include <algorithm& ...

  6. HDU多校Round 1

    Solved:5 rank:172 A.Maximum Multiple #include <stdio.h> #include <algorithm> #include &l ...

  7. hdu 5667 BestCoder Round #80 矩阵快速幂

    Sequence  Accepts: 59  Submissions: 650  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536 ...

  8. hdu 5643 BestCoder Round #75

    King's Game  Accepts: 249  Submissions: 671  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 6 ...

  9. hdu 5641 BestCoder Round #75

    King's Phone  Accepts: 310  Submissions: 2980  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

随机推荐

  1. 嵌入式开发之davinci--- 8127 和8148的区别

    1.主要的差别是8148有sata接口,8127没有 2.经过最近各方查找,应该是8107中把DSP砍掉了,8127如1楼所示 http://www.deyisupport.com/question_ ...

  2. mongodb配置主从模式

    Mongodb的replication主要有两种:主从和副本集(replica set).主从的原理和mysql类似,主节点记录在其上的所有操作oplog,从节点定期轮询主节点获取这些操作,然后对自己 ...

  3. where 1=1影响效率以及having和where的区别

    低效的“WHERE 1=1” 网上有不少人提出过类似的问题:“看到有人写了WHERE 1=1这样的SQL,到底是什么意 思?”. 其实使用这种用法的开发人员一般都是在使用动态组装的SQL. 让我们想像 ...

  4. bzoj1898 [Zjoi2005]Swamp 沼泽鳄鱼——矩阵快速幂

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1898 求到达方案数...还是矩阵快速幂: 能够到达就把邻接矩阵那里赋成1,有鳄鱼的地方从各处 ...

  5. Probabilistic interpretation

    Under the previous probabilistic assumptions on the data, least-squares regression corresponds to fi ...

  6. UEditor动态添加图片访问路径前缀

    在使用UEditor上传图片时发现上传图片后在编辑器中不能显示上传的图片,在这里是需要在jsp/config.json中设置图片访问路径前缀,即项目的根路径,在config.json只能填写字符串的配 ...

  7. sql的where条件中包含中文,查询不出来的处理方法

    SELECT  * FROM phonenumber_info where PROVANCE=N'广东' and  CITY=N'中山市'

  8. bzoj 3942: [Usaco2015 Feb]Censoring【kmp+栈】

    好久没写kmp都不会写了-- 开两个栈,s存当前串,c存匹配位置 用t串在栈s上匹配,栈每次入栈一个原串字符,用t串匹配一下,如果栈s末尾匹配了t则弹栈 #include<iostream> ...

  9. bzoj 1629: [Usaco2007 Demo]Cow Acrobats【贪心+排序】

    仿佛学到了贪心的新姿势-- 考虑相邻两头牛,交换它们对其他牛不产生影响,所以如果交换这两头牛能使这两头牛之间的最大值变小,则交换 #include<iostream> #include&l ...

  10. Akka源码分析-Cluster-Distributed Publish Subscribe in Cluster

    在ClusterClient源码分析中,我们知道,他是依托于“Distributed Publish Subscribe in Cluster”来实现消息的转发的,那本文就来分析一下Pub/Sub是如 ...