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的更多相关文章

  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. 分布式数据库DDM Sidecar模式负载均衡

    简介 1.分布式数据库中间件 DDM 分布式数据库中间件(Distributed Database Middleware)是解决数据库容量.性能瓶颈和分布式扩展问题的中间件服务,提供分库分表.读写分离 ...

  2. Android学习笔记-tween动画之java实现

    Android动画分为Tween动画和Frame动画,近期学习了,体tween动画,现在讲学习的心得以及相关知识介绍如下. Tween又称为补间动画,可以把对象进行缩小.放大.旋转和渐变等操作.   ...

  3. 用递归将嵌套的JSON对象遍历出来,转为二维数组

    如题所示,代码如下: var arJsonNesting = [{id:1,name:"zhang3" ,children:[{id:2,name:"zhang33&qu ...

  4. 协议解析Bug分析

    协议解析Bug分析 源自邮件协议RPC(远程过程调用)处理的Request请求数据包的bug.        一.Bug描写叙述 腾讯收购的Foxmailclient能够作为outlookclient ...

  5. Java 工具类 —— 定时器(Timer/TimerTask)

    import java.util.Timer; import java.util.TimerTask; public class Timer { .... public void schedule(T ...

  6. bzoj1999 (洛谷1099) 树网的核——dfs

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1999  https://www.luogu.org/problemnew/show/P109 ...

  7. GCD中各种队列和任务执行方式的组合

    一.概念回顾 1.GCD全称 Grand Central Dispatch ,是纯C语言,提供了非常多强大的函数,来进行系统线程的管理. 2.优势:GCD是苹果公司为多核的并行运算提出的解决方案.GC ...

  8. 用nginx进行同一个服务器下多域名的负载均衡配置

    用nginx进行同一个服务器下多域名的负载均衡配置 Nginx进行http负载均衡的模块是upstream Upstream可以进行多个配置,这样的话可以灵活的配置站点,但是注意的是upstream后 ...

  9. PCB 机器学习(ML.NET)初体验实现PCB加投率预测

    使用ML.NET建立PCB加投率模型对单一蚀刻工序进行加投率预测, 此实例为最简单预测,要想实现全流程加投率预测挑战难度还是挺大的,可以查看另一种关于大数据在PCB行业应用---加投率计算基本原理:P ...

  10. [Swift通天遁地]一、超级工具-(9)在地图视图MKMapView中添加支持交互动作的标注图标

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...