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. TypeError: db.addUser is not a function : @(shell):1:1 ——mongoDB创建新用户名密码的方法

    不多说,旧版本使用 db.addUser("root","root") 新版本使用这句会出现这个错误提示 TypeError: db.addUser is no ...

  2. wxpc

  3. GraphDatabase_action

    https://neo4j.com/docs/ #https://pypi.python.org/pypi/neo4j-driver/1.5.3from neo4j.v1 import GraphDa ...

  4. Delphi属性比对象的域有更强的功能

    8.4 Delphi自定义组件(3) http://tech.163.com 2006-04-29 11:49:34 来源: 清华大学出版社 网友评论0 条 论坛   3. 测试未安装的组件 在将新组 ...

  5. python 矩阵

    python的numpy库提供矩阵运算的功能,因此我们在需要矩阵运算的时候,需要导入numpy的包. 1.numpy的导入和使用 from numpy import *;#导入numpy的库函数 im ...

  6. 8-2 canvas专题-线条样式

    8-2 canvas专题-线条样式 学习要点 对第五章知识进行简单的回顾和总结 进一步讲解canvas绘图相关的知识点 第八章内容介绍 在第八章中我们将对以前的知识进行简单的回顾,着重对canvas绘 ...

  7. [App Store Connect帮助]六、测试 Beta 版本(3.2)管理测试员:邀请外部测试员

    在您上传至少一个构建版本之后,您可以邀请外部测试员(您组织之外的人员)使用“TestFlight Beta 版测试”来测试您的 App.为了使您的构建版本可用于外部测试,请创建一个群组.添加构建版本, ...

  8. centos docker 安装mysql 8.0

    centos 版本  CentOS Linux release 7.5.1804 (Core) 内核版本: 3.10.0-862.el7.x86_64 下载最新版mysql docker pull m ...

  9. MySql数据库创建表

    3.3.MySql数据库创建表 创建5个表: UserInfo用户基础表 Role 角色表 MenuInfo 菜单即控制表 Relation_Role_Menu 角色对应菜单关系表 RelaTion_ ...

  10. 题解报告:hdu 1035 Robot Motion(简单搜索一遍)

    Problem Description A robot has been programmed to follow the instructions in its path. Instructions ...