Sample Input
2
3
1 3 2
6
2 3 4 5 6 1
 
Sample Output
2
6

题意:给一个转置求它的循环长度

题解:分解成循环求最小公倍数

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 3221225473
#define N 100005
#define MIN 0
#define MAX 1000001 const int maxn = 3000005;
int a[maxn],vis[maxn],sum[maxn]; void fin(int num)
{
int tt;
for(int i = 2; i <= num; i++)
{
tt = 0;
while(num%i == 0)
{
num/=i;
tt++;
}
if(tt > sum[i])
sum[i] = tt;
}
} ll pow_mod(ll q,int n,ull mod)
{
if(n == 0)
return 1;
ll x = pow_mod(q,n/2,mod);
ll ans = (ll)x*x%mod;
if(n %2 == 1)
ans = ans *q % mod;
return ans;
} int main()
{
int n,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
ll ans;
for(int i = 1; i <= n; i++)
scanf("%d",&a[i]);
memset(vis,0,sizeof(vis));
memset(sum,0,sizeof(sum));
for(int i = 1; i <= n; i++)
{
if(vis[i])
continue;
int tmp = i;
int num = 0;
while(!vis[tmp])
{
vis[tmp] = 1;
tmp = a[tmp];
num ++;
}
//printf("num:%d\n",num);
fin(num);
} ans = 1;
for(int i = 2; i <= n; i++)
if(sum[i])
{
//printf("%d\n",sum[i]);
ans = (ans * pow_mod(i,sum[i],(ll)MOD))%MOD;
}
printf("%I64d\n",ans);
}
return 0;
}

  

hdu 5392的更多相关文章

  1. hdu 5392 Infoplane in Tina Town(数学)

    Problem Description There is a big stone with smooth surface in Tina Town. When people go towards it ...

  2. HDU 5392 BC #51

    就是求最大公倍数,但要用分解质因子求. 自己写的WA到爆.... #include<iostream> #include<stdio.h> #include<math.h ...

  3. HDU 5392 Infoplane in Tina Town

    Infoplane in Tina Town Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 524288/524288 K (Jav ...

  4. hdoj 5392 Infoplane in Tina Town

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5392 #include<stdio.h> #include<cstring> ...

  5. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  7. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  8. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 4006The kth great number(K大数 +小顶堆)

    The kth great number Time Limit:1000MS     Memory Limit:65768KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. 201621123043 《Java程序设计》第11周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1. 源代码阅读:多线程程序BounceThread 1.1 BallR ...

  2. python第三方库requests详解

    Requests 是用Python语言编写,基于 urllib,采用 Apache2 Licensed 开源协议的 HTTP 库.它比 urllib 更加方便,可以节约我们大量的工作,完全满足 HTT ...

  3. linux服务器操作系统,在相同环境下,哪个做lamp服务器更稳定点?哪个版本更稳定?

    随着国内WEB服务越来越多,如何才能选择一个合适的linux服务器操作系统?在国内用的最多的好像是红帽子系列也就是red hat系列,但有些版本缺乏稳定性.新手在选择操作系统的时候最好只用偶数版本,还 ...

  4. LeetCode & Q13-Roman to Integer-Easy

    Math String Description: Given a roman numeral, convert it to an integer. Input is guaranteed to be ...

  5. Python 黑客相关电子资源和书籍推荐

    原创 2017-06-03 玄魂工作室 玄魂工作室 继续上一次的Python编程入门的资源推荐,本次为大家推荐的是Python网络安全相关的资源和书籍. 在去年的双11送书的时候,其实送过几本Pyth ...

  6. XPath编写规则学习

    XPath编写规则学习   辅助工具:firefox安装findbugs,view Xpath firefox :Xpath验证方式:$x("xpath"); 粘贴xpath语句回 ...

  7. Angular 学习笔记 ( CDK - Accessibility )

    @angular/ckd 是 ng 对于 ui 组建的基础架构. 是由 material 团队开发与维护的, 之所以会有 cdk 看样子是因为在开发 material 的时候随便抽象一个层次出来给大家 ...

  8. BlueMix - IBM的Paas云计算平台

    Bluemix,2015年年中,IBM推出了名为Bluemix的云计算平台.这一"平台即服务"的PaaS云将帮助开发者更快的进行应用开发和部署.   Bluemix正是IBM回应这 ...

  9. SpringMvc(4-1)Spring MVC 中的 forward 和 redirect

    Spring MVC 中,我们在返回逻辑视图时,框架会通过 viewResolver 来解析得到具体的 View,然后向浏览器渲染.通过配置,我们配置某个 ViewResolver 如下: <b ...

  10. MySQL8.0 原子DDL

    Edit MySQL8.0 原子DDL 简介 MySQL8.0 开始支持原子 DDL(atomic DDL),数据字典的更新,存储引擎操作,写二进制日志结合成了一个事务.在没有原子DDL之前,DROP ...