Skip to content

Commit b2e81b0

Browse files
committed
Add problem Fixed-point theorem from UVA #math
1 parent 50b1882 commit b2e81b0

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

uva/13074.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
#define endl '\n'
5+
#define D(x) cout << #x << " = " << (x) << endl;
6+
7+
int mcm (int a, int b) {
8+
return (a * b) / __gcd(a, b);
9+
}
10+
11+
int main() {
12+
ios_base::sync_with_stdio(0); cin.tie(0);
13+
int n;
14+
while (cin >> n) {
15+
if (!n) break;
16+
17+
vector<int> v(n);
18+
for (auto &i: v) cin >> i;
19+
20+
vector<set<int>> count(n);
21+
vector<int> cur(n), next(n);
22+
23+
for (int i = 1; i <= n; ++i) cur[i - 1] = i;
24+
25+
vector<int> cycle(n, 0);
26+
bool found = true;
27+
while (found) {
28+
found = false;
29+
for (int i = 0; i < n; ++i) {
30+
int t = cur[v[i] - 1];
31+
next[i] = t;
32+
if (count[i].count(t) == 0) {
33+
count[i].insert(t);
34+
cycle[i] ++;
35+
found = true;
36+
}
37+
}
38+
cur = next;
39+
}
40+
41+
set<int> st(cycle.begin(), cycle.end());
42+
int ans = 1;
43+
for (auto i: st) {
44+
ans = mcm(ans, i);
45+
}
46+
47+
cout << ans << endl;
48+
}
49+
50+
return 0;
51+
}

0 commit comments

Comments
 (0)