/*hdu6038[找规律+循环节] 2017多校1*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const double eps=1e-;
const int inf=0x3f3f3f3f;
const int mod=;
int n,m,lop,kase=,maxlop;
int a[],b[],mark[];
LL Arep[],Brep[];
LL fastpow(LL a,LL b){
LL ret=,x=a;
while(b){
if(b&){
ret=(ret*x)%mod;
}
x=(x*x)%mod;
b>>=;
}
return ret;
}
void dfs(int now,int dps){
if(mark[now]){
Arep[dps]++;
return;
}
mark[now]=;
dfs(a[now],dps+);
}
void dfs2(int now,int dps){
if(mark[now]){
Brep[dps]++;
return;
}
mark[now]=;
dfs2(b[now],dps+);
}
void solve(){
maxlop=;
for(int i=;i<n;i++){
if(!mark[a[i]]){
dfs(i,);
}
}
memset(mark,,sizeof(mark));
for(int i=;i<m;i++){
if(!mark[b[i]]){
dfs2(i,);
}
}
memset(mark,,sizeof(mark));
LL ans=,sum=;
for(int i=;i<=n;i++){
if(Arep[i]){
ans=;
for(int j=;j*j<=i;j++){
if(i%j==){
ans=(ans+(Brep[j]%mod)*(j%mod))%mod;
if(j*j!=i){
ans=(ans+(Brep[i/j]%mod)*((i/j)%mod))%mod;
}
}
}
sum=(sum*fastpow(ans,Arep[i]))%mod;
}
}
printf("Case #%d: %lld\n",kase++,sum);
}
int main(){
//freopen("1006.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(~scanf("%d%d",&n,&m)){
memset(mark,,sizeof(mark));
memset(Arep,,sizeof(Arep));
memset(Brep,,sizeof(Brep));
for(int i=;i<n;scanf("%d",&a[i]),i++);
for(int i=;i<m;scanf("%d",&b[i]),i++);
solve();
}
return ;
}

hdu6038[找规律+循环节] 2017多校1的更多相关文章

  1. hihocode 1584 : Bounce (找规律)(2017 北京网络赛G)

    题目链接 比赛时随便找了个规律,然后队友过了.不过那个规律具体细节还挺烦的.刚刚偶然看到Q巨在群里提到的他的一个思路,妙啊,很好理解,而且公式写起来也容易.OrzQ巨 #include<bits ...

  2. 51nod 1126 - 求递推序列的第N项 - [找规律]

    题目链接:https://cn.vjudge.net/problem/51Nod-1126 有一个序列是这样定义的:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + ...

  3. A Simple Problem with Integers 循环节 修改 平方 找规律 线段树

    A Simple Problem with Integers 这个题目首先要打表找规律,这个对2018取模最后都会进入一个循环节,这个循环节的打表要用到龟兔赛跑. 龟兔赛跑算法 floyed判环算法 ...

  4. 2017多校第一套&&hdu6038 思维 数学

    链接  http://acm.hdu.edu.cn/showproblem.php?pid=6038 题意: 给你一个a序列,代表0到n-1的排列:一个b序列代表0到m-1的排列.问你可以找出多少种函 ...

  5. 2017ACM暑期多校联合训练 - Team 1 1011 HDU 6043 KazaQ's Socks (找规律)

    题目链接 Problem Description KazaQ wears socks everyday. At the beginning, he has n pairs of socks numbe ...

  6. hdoj1005(循环,找规律)

    Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1 ...

  7. 特征根法求通项+广义Fibonacci数列找循环节 - HDU 5451 Best Solver

    Best Solver Problem's Link Mean: 给出x和M,求:(5+2√6)^(1+2x)的值.x<2^32,M<=46337. analyse: 这题需要用到高中的数 ...

  8. Codeforces Round #450 (Div. 2) B. Position in Fraction【数论/循环节/给定分子m 分母n和一个数c,找出c在m/n的循环节第几个位置出现,没出现过输出-1】

    B. Position in Fraction time limit per test 1 second memory limit per test 256 megabytes input stand ...

  9. 杭电多校第十场 hdu6432 Cyclic 打表找规律

    Cyclic Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)Total Su ...

随机推荐

  1. 洛谷 P2383 狗哥玩木棒

    题目背景 狗哥又趁着语文课干些无聊的事了... 题目描述 现给出一些木棒长度,那么狗哥能否用给出的木棒(木棒全用完)组成一个正方形呢? 输入输出格式 输入格式: 输入文件中的第一行是一个整数n表示测试 ...

  2. python爬虫之路——对字符串的处理

    对字符串的处理分类:分段,连接,剔除,提取,综合 连接:+,* +(加法)的使用 a='i' b=' love' c=' you' print(a+b+c) #return i love you *( ...

  3. redis的一些问题总结,转载自infoq

    Redis是时下比较流行的Nosql技术.在优酷我们使用Redis Cluster构建了一套内存存储系统,项目代号蓝鲸.到目前为止集群有700+节点,即将达到作者推荐的最大集群规模1000节点.集群从 ...

  4. codeforce Gym 100500H ICPC Quest (简单dp)

    题意:给一个nXm的矩阵,上面有一些数字,从左上角出发,每次只能往右或者往下,把沿途的数字加起来,求到达右下角的最大值是多少. 题解:简单的一个dp,设f[i][j]为到达i行j列的最大值,f[i][ ...

  5. TextView中使用Linkify添加超链接

       首先,在TextView所属xml配置文件中,直接添加android:autoLink特性即可,它支持一个或多个(用分割线)自定义的值:none.web.email.phone或all. 另外, ...

  6. key directories in the linux file system

    Key directories in the file system: */: Root directory (base of file system) /bin: Executable progra ...

  7. hbuilder 夜神模拟器调试方法

    1.首先下载好夜神模拟器2.查找已经安装的夜神模拟的端口,这里说一下夜神模拟器默认端口是62001,但是有些版本可能不是这个端口,怎么查找到底是哪个端口呢?按照如下顺序进行就可以查找到你按装的夜神模拟 ...

  8. C Library - <limits.h>

    Introduction The limits.h header determines various properties of the various variable types. The ma ...

  9. Js笔记 14

      <script> // <!-- 课 对象   // //对象的创建方法 // 1.var obj = {} plainobject 对象字面量 对象直接量 // 2.构造函数 ...

  10. vuePress的使用

    今天来玩一玩vuePress的使用,用markdown来编辑一个页面网站,这里谈论到了简单使用,细节可以去官网上去查看 开始安装 项目依赖 // package.json { "name&q ...