HDU 5392 Infoplane in Tina Town
来源:互联网 发布:伪随机数生成算法 编辑:程序博客网 时间:2024/05/16 01:42
Infoplane in Tina Town
Time Limit: 14000/7000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 805 Accepted Submission(s): 168
Problem Description
There is a big stone with smooth surface in Tina Town. When people go towards it, the stone surface will be lighted and show its usage. This stone was a legacy and also the center of Tina Town’s calculation and control system. also, it can display events in Tina Town and contents that pedestrians are interested in, and it can be used as public computer. It makes people’s life more convenient (especially for who forget to take a device).
Tina and Town were playing a game on this stone. First, a permutation of numbers from1 to n were displayed on the stone. Town exchanged some numbers randomly and Town recorded this process by macros. Town asked Tine,”Do you know how many times it need to turn these numbers into the original permutation by executing this macro? Tina didn’t know the answer so she asked you to find out the answer for her.
Since the answer may be very large, you only need to output the answer modulo3∗230+1=3221225473 (a prime).
Tina and Town were playing a game on this stone. First, a permutation of numbers from
Since the answer may be very large, you only need to output the answer modulo
Input
The first line is an integer T representing the number of test cases. T≤5
For each test case, the first line is an integern representing the length of permutation. n≤3∗106
The second line containsn integers representing a permutation A1...An . It is guaranteed that numbers are different each other and all Ai satisfies ( 1≤Ai≤n ).
For each test case, the first line is an integer
The second line contains
Output
For each test case, print a number ans representing the answer.
Sample Input
231 3 262 3 4 5 6 1
Sample Output
26
Source
BestCoder Round #51 (div.2)
Recommend
hujie | We have carefully selected several similar problems for you: 5395 5394 5393 5390 5389
给出一个序列,求变换几次可以回到原来的位置。比如 1 3 2 ,3 不在原来的位置,变到3位置,次数加1,2变到2,次数+1.得到2.。
做法就是分解循环长度。然后求下最小公倍数。但是不能直接用lcm求最小公倍数。。我们可以考虑用质数分解来求,即公共的质因子乘每个数本身的质因子。
#include<cmath>#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;typedef long long ll;typedef unsigned long long ull;int a[3000010];int vis[3000010];int b[3000010];const ll mod=3221225473;inline int read(){ char ch; for (ch=getchar(); ch<48||ch>57;) ch=getchar(); int d=0; for (; ch>47&&ch<58; ch=getchar()) d=d*10+ch-48; return d;}ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b);}ll lcm(ll a,ll b){ return a/gcd(a,b)*b;}int main(){ int t,n,i,j; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=1; i<=n; i++) a[i]=read(); memset(vis,0,sizeof(vis)); memset(b,0,sizeof(b)); for(i=1; i<=n; i++) { if(!vis[i]) { int t=i; int s=0; while(!vis[t]) { s++; vis[t]=1; t=a[t]; } for(j=2; j*j<=s; j++) { int cnt=0; while(s%j==0) { cnt++; s/=j; } b[j]=max(b[j],cnt); //统计公共的质因子。 } if(s>1) b[s]=max(b[s],1); } } // cout<<lcm(121,11)<<endl; ull ans=1; for(i=2; i<=n; i++) for(j=1; j<=b[i]; j++) ans=ull(ans)*i%mod; cout<<ans<<endl; }}
0 0
- hdu 5392 Infoplane in Tina Town
- HDU 5392 Infoplane in Tina Town
- HDU - 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 (质因子分解求最小公倍数)
- HDU-5392 Infoplane in Tina Town(分解质因数法求最小公倍数)
- HDU 5392 Infoplane in Tina Town (置换+质因子分解求最小公倍数)
- HDOJ-5392 Infoplane in Tina Town(置换群循环节长度)
- B、Infoplane in Tina Town-----(BestCoder Round #51 (div.2) )
- Zball in Tina Town HDU
- hdu 5391 Zball in Tina Town
- hdu 5391 Zball in Tina Town (数学)
- hdu 5391 Zball in Tina Town
- hdu 5391 Zball in Tina Town
- elasticsearch 基础
- SQLite3常用对象和函数
- POJ 1149 PIGS 最大流
- 关于页面、可视区、屏幕等一些相关的宽高属性
- UVA 10294 Arif in Dhaka (置换polya)
- HDU 5392 Infoplane in Tina Town
- exchange2013 sp1安装完成后的一些配置
- Happy Number
- Linux下安装java运行环境
- HDFS-1.简单介绍及shell操作
- 每天一个Linux命令-19(which,whereis,locate,find区别)
- struts2学习笔记(十一)文件上传
- ArrayList的多态性
- .xcodeproj目录中各文件作用及SVN/Git同步