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: ...
随机推荐
- 【bzoj1406】[AHOI2007]密码箱
x2 ≡ 1 mod n => x2 = k * n + 1 => n | (x + 1) * (x - 1) 令n = a * b,则 (a | x + 1 且 b | x - 1) 或 ...
- PHP mysql 连接ipV6地址
需要在PHP页面中通过ipv6连接数据库,但是发现无论是用mysql_connect还是mysqli_connect,如果host是ipv6格式,就不能正常连接,会提示“php_network_get ...
- 在vs2017中创建Node.js项目
https://github.com/Microsoft/nodejstools/wiki/Projects 1. 安装vs2017的时候,需要勾选Node.js 2.新建项目的时候,选择其他语言,然 ...
- 洛谷 P1181,1182 数列分段Section
数列分段Section I 题目描述 对于给定的一个长度为N的正整数数列A[i],现要将其分成连续的若干段,并且每段和不超过M(可以等于M),问最少能将其分成多少段使得满足要求. 输入输出格式 输入格 ...
- bzoj 4337 树的同构
4337: BJOI2015 树的同构 Description 树是一种很常见的数据结构. 我们把N个点,N-1条边的连通无向图称为树. 若将某个点作为根,从根开始遍历,则其它的点都有一个前驱,这个树 ...
- 16. Ext.ux.TabCloseMenu插件的使用(TabPanel右键关闭菜单) 示例
转自:https://crabdave.iteye.com/blog/327978 Ext.ux.TabCloseMenu插件的使用(TabPanel右键关闭菜单) 示例 效果: 创建调用的HTML: ...
- MySQL基础 — 常用命令
一.连接MySQL 格式: mysql -h主机地址 -u用户名 -p用户密码 1.连接到本机上的MySQ: 首先在打开cmd窗口,输入mysql -uroot -p ,然后空格进入MySQL控制台, ...
- 清北考前刷题day7早安
- 51nod2006 飞行员配对(二分图最大匹配)
2006 飞行员配对(二分图最大匹配) 题目来源: 网络流24题 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 第二次世界大战时期,英国皇家空军从沦陷国 ...
- WCF 相关配置
WCF错误:413 Request Entity Too Large 在我们用WCF传输数据的时候,如果启用默认配置,传输的数据量过大,经常会出这个错误. WCF包含服务端与客户端,所以这个错误可能出 ...