hdu5392--Infoplane in Tina Town(置换群+质因子分解求最小公倍数)
来源:互联网 发布:mac office 登陆 编辑:程序博客网 时间:2024/04/29 12:09
题目链接:点击打开链接
题目大意:给出一种操作a[1],a[2],,,,a[n],代表每交换一次,1位置的数到a[1]位置,2位置的数到a[2]位置,,,
问最终交换多少次可以恢复初始的情况。
题目给出一个置换,要求置换的次数,也就是所有轮换个数的最小公倍数。首先求出所有轮换的个数,然后求最小公倍数的时候不能用gcd,因为Mod的取余太大,所以用质因子分解,统计每个质因子出现的最多次数,计算最终的值。
#include <cstdio>#include <cstring>#include <queue>#include <set>#include <vector>#include <cmath>#include <map>#include <stack>#include <algorithm>#include <time.h>using namespace std ;#pragma comment(linker, "/STACK:102400000,102400000")#define LL __int64#define INF 0x3f3f3f3f#define PI acos(-1.0)#define maxn 3000010const LL Mod = 3221225473 ;int a[maxn] , sum[maxn] , vis[maxn] ;int main() { int t , n , i , j , num , temp , cnt ; LL ans ; scanf("%d", &t) ; while( t-- ) { scanf("%d", &n) ; for(i = 1 ; i <= n ; i++) { scanf("%d", &a[i]) ; sum[i] = vis[i] = 0 ; } for(i = 1 ; i <= n ; i++) { if( vis[i] ) continue ; vis[i] = 1 ; num = 1 ; j = a[i] ; while( !vis[j] ) { num++ ; vis[j] = 1 ; j = a[j] ; } for(j = 2 , temp = num ; j*j <= num ; j++) { if( temp%j ) continue ; cnt = 0 ; while( temp%j == 0 ) { temp /= j ; cnt++ ; } sum[j] = max(sum[j],cnt) ; if( temp == 1 ) break ; } if( temp > 1 ) sum[temp] = max(sum[temp],1) ; } for(i = 2 , ans = 1 ; i <= n ; i++) { for(j = 0 ; j < sum[i] ; j++) ans = ans*i%Mod ; } printf("%I64d\n", ans) ; } return 0 ;}
1 0
- hdu5392--Infoplane in Tina Town(置换群+质因子分解求最小公倍数)
- HDU 5392 Infoplane in Tina Town (置换+质因子分解求最小公倍数)
- hdu 5392-Infoplane in Tina Town(质因子分解求最小公倍数)
- hdu 5392 Infoplane in Tina Town (质因子分解求最小公倍数)
- HDU-5392 Infoplane in Tina Town(分解质因数法求最小公倍数)
- hdu 5392 Infoplane in Tina Town (置换循环长度)
- HDOJ-5392 Infoplane in Tina Town(置换群循环节长度)
- Infoplane in Tina Town HDU
- hdu 5392 Infoplane in Tina Town
- HDU 5392 Infoplane in Tina Town
- HDOJ 5392 Infoplane in Tina Town LCM
- HDU - 5392 Infoplane in Tina Town
- hdu 5392 Infoplane in Tina Town(快速幂)
- B、Infoplane in Tina Town-----(BestCoder Round #51 (div.2) )
- Zball in Tina Town
- Zball in Tina Town
- hdu5391Zball in Tina Town
- 分解质因子、求最大公约数/最小公倍数、索引的实现示例
- 谷歌离线地图开发四步曲
- 部署Struts遇到“There is no Action mapped for namespace [/] and action name [...] associated with .."问题
- POJ 3009 Curling 2.0
- 从零开始教你3D打印机怎么使用
- Struts2中的OGNL详解
- hdu5392--Infoplane in Tina Town(置换群+质因子分解求最小公倍数)
- SDUT2128 排序二叉树的中序遍历
- 不用库函数 求解立方根
- K-NN算法
- ios 仿知乎手势滑动效果
- 困扰我国3D打印发展的常见问题解读
- 借助Apache Cordova构建混合移动应用程序
- cropper .net后台截图
- 对于多对一关联的时候使用JSON方式显示不出来的问题