#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int p=1e5+;
const int maxn=1e5+;
const int N=1e5+;
const int M=5e3+;
bool ok[maxn];
int prime[maxn],phi[maxn],cnt;
int a,b,n;
int u[N],v[N];
int dp[][M][];
//int dp[2*M][M][2];
void init()
{
phi[]=;
for(ll i=; i<maxn; ++i)
{
if(!ok[i])
{
prime[cnt++]=i;
phi[i]=i-;
}
for(int j=; j<cnt; ++j)
{
if(i*prime[j]>=maxn)break;
ok[i*prime[j]]=;
if(i%prime[j]==)
{
phi[i*prime[j]]=phi[i]*prime[j];//prime[j]是i的因子 prime[j]的素因子项包含在i的素因子项里
break;
}
else phi[i*prime[j]]=phi[i]*(prime[j]-);//prime[j]与i互质 phi[i*prime[j]=phi[i]*phi[prime[j]]
}
}
}
int modpow(int x,int n,int mod)
{
int ans=;
for(; n; n/=,x=1ll*x*x%mod)
if(n&)ans=1ll*ans*x%mod;
return ans;
}
int f(int num,int mod)
{
if(mod==)return ;
if(num==)return b%mod;
return modpow(b,f(num-,phi[mod])+phi[mod],mod);
}
int main()
{
init();
while(scanf("%d%d",&a,&b)!=EOF)
{
scanf("%d",&n);
for(int i=; i<=n; ++i)
{
scanf("%d",&u[i]);
u[i]=modpow(a,f(u[i],phi[p])+phi[p],p);
}
for(int i=; i<=n; ++i)
{
scanf("%d",&v[i]);
v[i]=modpow(a,f(v[i],phi[p])+phi[p],p);
}
memset(dp,,sizeof dp);
u[]=v[]=p+;//保证和第二项不同 /**for(int j=1;j<=n;j++){
for(int i=j;i<=n+j;i++){
dp[i][j][0]=max(dp[i-1][j-1][0]+u[j]*(u[j-1]==u[j]),dp[i-1][j-1][1]+u[j]*(v[j-1]==u[j]));
dp[i][j][1]=max(dp[i-1][j-1][1]+v[j]*(v[j-1]==v[j]),dp[i-1][j-1][0]+v[j]*(u[j-1]==v[j]));
}
}*/
for(int k=; k<=n; ++k)
{
int i=k&;
//cout<<i<<" "<<(i^1)<<'\n';
for(int j=; j<=n; ++j)
{
dp[i][j][]=;
dp[i][j][]=;
}
///滚动 ///u取第k位
///v取第j位
///如何保证无后效性??
for(int j=; j<=n; ++j)
{
if(k>)
{
dp[i][j][]=max(dp[i][j][],dp[i^][j][]+u[k]*(u[k]==u[k-]));///u[k]的前一位可以是u[k-1]
dp[i][j][]=max(dp[i][j][],dp[i^][j][]+u[k]*(u[k]==v[j]));///u[k]前一位可以是v的任一位
}
if(j>)
{
dp[i][j][]=max(dp[i][j][],dp[i][j-][]+v[j]*(v[j]==u[k]));///v[j]的前一位可以是u的任一位
dp[i][j][]=max(dp[i][j][],dp[i][j-][]+v[j]*(v[j]==v[j-]));///v[j]的前一位可以是v[j-1]
}
} }
printf("%d\n",max(dp[n&][n][],dp[n&][n][]));
}
return ;
}

Xyjj’s sequence的更多相关文章

  1. oracle SEQUENCE 创建, 修改,删除

    oracle创建序列化: CREATE SEQUENCE seq_itv_collection            INCREMENT BY 1  -- 每次加几个              STA ...

  2. Oracle数据库自动备份SQL文本:Procedure存储过程,View视图,Function函数,Trigger触发器,Sequence序列号等

    功能:备份存储过程,视图,函数触发器,Sequence序列号等准备工作:--1.创建文件夹 :'E:/OracleBackUp/ProcBack';--文本存放的路径--2.执行:create or ...

  3. DG gap sequence修复一例

    环境:Oracle 11.2.0.4 DG 故障现象: 客户在备库告警日志中发现GAP sequence提示信息: Mon Nov 21 09:53:29 2016 Media Recovery Wa ...

  4. Permutation Sequence

    The set [1,2,3,-,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

  5. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  6. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  7. [LeetCode] Verify Preorder Sequence in Binary Search Tree 验证二叉搜索树的先序序列

    Given an array of numbers, verify whether it is the correct preorder traversal sequence of a binary ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Permutation Sequence 序列排序

    The set [1,2,3,…,n] contains a total of n! unique permutations. By listing and labeling all of the p ...

随机推荐

  1. ---Mock---基本使用

    一.mock解决的问题 开发时,后端还没完成数据输出,前端只好写静态模拟数据.数据太长了,将数据写在js文件里,完成后挨个改url.某些逻辑复杂的代码,加入或去除模拟数据时得小心翼翼.想要尽可能还原真 ...

  2. Servlet,HttpServletRequest 和 HttpServletResponse

    今天是周六,老子加班,还可吧, 哈哈哈哈哈哈哈哈哈哈哈哈哈 此次更新的内容是HttpServletRequest 和 HttpServletResponse 昨天复习了一部分内容,今天又把剩下的看完. ...

  3. 使用before和after双伪元素清除浮动

    使用方法: .clearfix:before,.clearfix:after { content:"."; display:table; } .clearfix:after { c ...

  4. PHP数据结构基本概念

    原文:https://www.cnblogs.com/crystaltu/p/6408484.html 学习任何一种技术都应该先清楚它的基本概念,这是学习任何知识的起点!本文是讲述数据结构的基本概念, ...

  5. Min-Max 容斥的证明

    这里有 Min-Max 容斥的证明以及唯一一道博主做过的例题... 上个结论: \[Min\{S\}=\sum_{T\subseteq S,T\not=\varnothing}(-1)^{|T|-1} ...

  6. django模板传入参数的处理方式与反向生成url

    前端模板传入参数的处理方式 1.传入单个参数: 前端使用href="/sel-{{ row.0 }}.html, url使用url(r'sel-(.+).html',home.index), ...

  7. ThinkPHP5微信支付扩展库(超级简单, 超级超好用!)

    ThinkPHP5微信支付最新扩展库(2017年9月24日). 我的想法很简单,就是只需要调用一个静态方法就可以完成支付,查询,退款,查账等等, 无需重复造轮子, 专注自己业务!欢迎到Github查看 ...

  8. jdk8中几个核心的函数式接口笔记

    1. Function接口 /** * function 接口测试 * function 函数只能接受一个参数,要接受两个参数,得使用BiFunction接口 */ public class Func ...

  9. 来到园子的第two天!!!!!

    经过这几天的打字练习  从练习的第一天到今天(应该是第三天吧) 从67到133字/分钟,我练的是英文文章测试,总的来说挺不容易 ,感觉后几天提升就不好提了呀 不说废话了  简单说一下今天的收获吧 都是 ...

  10. HTML5初识

    HTML:超文本标记语言 HTML文档树结构 标签:有一对<>组成的,标签不区分大小写,大多数都是成对出现,有开始标签和结束标签,但也有单个出现的自闭和标签 标签属性:以键值对放在标签中, ...