码迷,mamicode.com
首页 > 其他好文 > 详细

hdoj 5392 Infoplane in Tina Town

时间:2015-08-16 18:00:37      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5392

 1 #include<stdio.h>
 2 #include<cstring>
 3 #include<cmath>
 4 #include<algorithm>
 5 #include<set>
 6 using namespace std;
 7 const int MAXN = 3*1e6+10;
 8 const unsigned int MOD = 3221225473;
 9 int n, T;
10 int a[MAXN];
11 int vis[MAXN];
12 int num[MAXN];
13 int tmp;
14 int t;
15 int ct;
16 long long ans;
17 set<int>s;
18 set<int>::iterator it;
19 int cnt[MAXN];
20 int main(){
21     scanf("%d",&T);
22     while(T--){
23         t = 1;
24         scanf("%d",&n);
25         for( int i = 1; i <= n; ++i){
26             scanf("%d",&a[i]);
27         }
28         memset(vis,0,sizeof(vis));
29         for( int i = 1; i <= n; ++i){
30             if( vis[i] != 0 )
31                 continue;
32             tmp = a[a[i]];
33             num[t] = 1;
34             while( a[i] != tmp ){
35                 vis[tmp] = 1;
36                 tmp = a[tmp];
37                 num[t]++;
38             }
39             vis[tmp] = 1;
40             t++;
41         }
42         memset(cnt,0,sizeof(cnt));
43         ans = 1;
44         for(int i = 1; i < t; ++i){
45             for( int d = 2; d <= num[i]; ++d){
46                 ct = 0;
47                 while( num[i] % d == 0 ){
48                     num[i] = num[i] / d;
49                     ct++;
50                 }
51                 s.insert(d);
52                 cnt[d] = max(cnt[d],ct);
53             }
54         }
55         for(it = s.begin();it!=s.end();++it){
56             ans = ans*pow((*it),cnt[*it]);
57             ans %= MOD;
58         }
59         printf("%I64d\n",ans);
60     }
61 }

 

hdoj 5392 Infoplane in Tina Town

标签:

原文地址:http://www.cnblogs.com/blueprintf/p/4734602.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!