题意:给一个置换,求最小循环长度对p取模的结果

思路:一个置换可以写成若干循环的乘积,最小循环长度为每个循环长度的最小公倍数。求最小公倍数对p取模的结果可以对每个数因式分解,将最小公倍数表示成质数幂的乘积形式,然后用快速幂取模,而不能一边求LCM一边取模。

由于这题数据量太大,需要用到输入挂,原理是把文件里面的东西用fread一次性读到内存。

输入挂模板:

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
namespace IO {
const static int maxn = << ;
static char buf[maxn], *pbuf = buf, *End;
void init() {
int c = fread(buf, , maxn, stdin);
End = buf + c;
}
int &readint() {
static int ans;
ans = ;
while (pbuf != End && !isdigit(*pbuf)) pbuf ++;
while (pbuf != End && isdigit(*pbuf)) {
ans = ans * + *pbuf - '0';
pbuf ++;
}
return ans;
}
}

源程序:

  1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#pragma comment(linker, "/STACK:10240000")
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define copy(a, b) memcpy(a, b, sizeof(a)) typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull; //#ifndef ONLINE_JUDGE
void RI(vector<int>&a,int n){a.resize(n);for(int i=;i<n;i++)scanf("%d",&a[i]);}
void RI(){}void RI(int&X){scanf("%d",&X);}template<typename...R>
void RI(int&f,R&...r){RI(f);RI(r...);}void RI(int*p,int*q){int d=p<q?:-;
while(p!=q){scanf("%d",p);p+=d;}}void print(){cout<<endl;}template<typename T>
void print(const T t){cout<<t<<endl;}template<typename F,typename...R>
void print(const F f,const R...r){cout<<f<<", ";print(r...);}template<typename T>
void print(T*p, T*q){int d=p<q?:-;while(p!=q){cout<<*p<<", ";p+=d;}cout<<endl;}
//#endif
template<typename T>bool umax(T&a, const T&b){return b<=a?false:(a=b,true);}
template<typename T>bool umin(T&a, const T&b){return b>=a?false:(a=b,true);} const double PI = acos(-1.0);
const int INF = 1e9 + ;
const double EPS = 1e-8; /* -------------------------------------------------------------------------------- */ const int maxn = 3e6 + ;
const unsigned int md = ; vector<int> prime;
vector<vector<pii> > R;
bool vis[maxn], flag[maxn];
int power[maxn], a[maxn]; void init() {
for (ll i = ; i < maxn; i ++) {
if (flag[i]) continue;
prime.pb(i);
for (ll j = i * i; j < maxn; j += i) {
flag[j] = true;
}
}
} void add(int x) {
vector<pii> buf;
for (int i = ; x > && i < prime.size(); i ++) {
int c = ;
while (x % prime[i] == ) {
c ++;
x /= prime[i];
}
if (c) buf.pb(mp(i, c));
}
R.pb(buf);
} unsigned int powermod(int a, int b, unsigned int md) {
if (b == ) return ;
ull buf = powermod(a, b >> , md);
buf = buf * buf % md;
if (b & ) buf = buf * a % md;
return buf;
} namespace IO {
const static int maxn = << ;
static char buf[maxn], *pbuf = buf, *End;
void init() {
int c = fread(buf, , maxn, stdin);
End = buf + c;
}
int &readint() {
static int ans;
static char ch;
ans = ;
while (pbuf != End && !isdigit(*pbuf)) pbuf ++;
while (pbuf != End && isdigit(*pbuf)) {
ans = ans * + *pbuf - '0';
pbuf ++;
}
return ans;
}
} int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // ONLINE_JUDGE
int T, n;
IO::init();
T = IO::readint();
init();
while (T --) {
n = IO::readint();
for (int i = ; i <= n; i ++) {
a[i] = IO::readint();
}
fillchar(vis, );
R.clear();
for (int i = ; i <= n; i ++) {
if (vis[i] || a[i] == i) continue;
int cnt = ;
for (int j = i; !vis[j]; j = a[j]) {
vis[j] = true;
cnt ++;
}
add(cnt);
}
fillchar(power, );
int maxpower = ;
for (int i = ; i < R.size(); i ++) {
for (int j = ; j < R[i].size(); j ++) {
umax(power[R[i][j].X], R[i][j].Y);
umax(maxpower, R[i][j].X);
}
}
unsigned int ans = ;
for (int i = ; i <= maxpower; i ++) {
ans = ((ull)ans * powermod(prime[i], power[i], md)) % md;
}
printf("%u\n", ans);
}
return ;
}

[hdu5392 Infoplane in Tina Town]置换的最小循环长度,最小公倍数取模,输入挂的更多相关文章

  1. hdu5392 Infoplane in Tina Town(LCM)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Infoplane in Tina Town Time Limit: 14000/ ...

  2. HDU 5392 Infoplane in Tina Town

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

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

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

  4. hdoj 5392 Infoplane in Tina Town

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

  5. HDU-5391 Zball in Tina Town

    (n-1)!/n 就是如果n为素数,就等于n-1else为0. 求素数表: Zball in Tina Town Time Limit: 3000/1500 MS (Java/Others) Memo ...

  6. (hdu)5391 Zball in Tina Town

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5391 Problem Description Tina Town is a friendl ...

  7. hdu5391 Zball in Tina Town(威尔逊定理)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Zball in Tina Town Time Limit: 3000/1500 ...

  8. hdu 5391 Zball in Tina Town(打表找规律)

    问题描述 Tina Town 是一个善良友好的地方,这里的每一个人都互相关心. Tina有一个球,它的名字叫zball.zball很神奇,它会每天变大.在第一天的时候,它会变大11倍.在第二天的时候, ...

  9. C#版 - HDUoj 5391 - Zball in Tina Town(素数) - 题解

    版权声明: 本文为博主Bravo Yeung(知乎UserName同名)的原创文章,欲转载请先私信获博主允许,转载时请附上网址 http://blog.csdn.net/lzuacm. HDUoj 5 ...

随机推荐

  1. 对短路变形POJ3615

    Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are ...

  2. Gradle系列之Groovy基础篇

    原文发于微信公众号 jzman-blog,欢迎关注交流. 上一篇学习了 Gradle 的入门知识,Gradle 基于 Groovy,今天学习一下 Groovy 的基础知识,Groovy 是基于 JVM ...

  3. C#开发BIMFACE系列31 服务端API之模型对比2:获取模型对比状态

    系列目录     [已更新最新开发文章,点击查看详细] 在上一篇<C#开发BIMFACE系列30 服务端API之模型对比1:发起模型对比>中发起了2个模型对比,由于模型对比是在BIMFAC ...

  4. 解析网站爬取腾讯vip视频

    今天用油猴脚本vip一件解析看神奇队长.想到了问题,这个页面应该是找到了视频的api的接口,通过接口调用获取到了视频的地址. 那自己找腾讯视频地址多费劲啊,现在越来越多的参数,眼花缭乱的. 那我就找到 ...

  5. srt字幕翻译

    需要把字幕名改成i.txt 有有道和谷歌 代码: #Author:Chenglong Qian #Copyright :Chenglong Qian import json import reques ...

  6. php--static用法

    static关键字声明一个属性或方法是和类相关的,而不是和类的某个特定的实例相关,因此,这类属性或方法也称为“类属性”或“类方法”. 如果访问控制权限允许,可不必创建该类对象而直接使用类名加两个冒号“ ...

  7. DEDE中自定义表单HTML 怎么写

    用DEDE嵌套网站时,有时我们需要添加自定义字段,而自定义字段的HTML样式如何设置呢? 功能地图(核心/频道模型/内容模型管理/)——普通文章的修改——字段管理——你的自定义字段的修改——最下面自定 ...

  8. js 实现动画功能,完整解析插件版 可更改配置参数[animate.js]

    前言:         本人纯小白一个,有很多地方理解的没有各位大牛那么透彻,如有错误,请各位大牛指出斧正!小弟感激不尽.         本篇文章为您分析一下原生JS写一个运动插件 基本功能: 补充 ...

  9. HDU 5725 Game

    1. 笔记 题意是求距离的期望(距离仍指连接两点且有效的路径长度的最小值).直观想象可以发现,该距离与曼哈顿距离相比最多多2(可以构造这样的路径). 答案=(任意两点曼哈顿距离的总和 - 至少有一点是 ...

  10. 徐州赛区网络预赛 D Easy Math

    比赛快结束的适合看了一下D题,发现跟前几天刚刚做过的HDU 5728 PowMod几乎一模一样,当时特兴奋,结果一直到比赛结束都一直WA.回来仔细一琢磨才发现,PowMod这道题保证了n不含平方因子, ...