Description\text{Description}Description
Given an array a[], swap random 2 number of them for 3n or (7n+1) times.\text{Given an array }a[],\text{ swap random 2 number of them for }3n\text{ or }(7n+1)\text{ times.}Given an array a[], swap random 2 number of them for 3n or (7n+1) times.
Please compute how many times for swaping.\text{Please compute how many times for swaping.}Please compute how many times for swaping.
Solution\text{Solution}Solution
It’s easy to know that if we keep swaping a[i] and a[a[i]], they’ll always\text{It's easy to know that if we keep swaping }a[i]\text{ and }a[a[i]],\text{ they'll always}It’s easy to know that if we keep swaping a[i] and a[a[i]], they’ll always
goes a[i]=i at last.\text{goes }a[i]=i\text{ at last.}goes a[i]=i at last.
Counting times we’ve done that so that ∀i,a[i]=i. Check its parity.\text{Counting times we've done that so that }\forall i,a[i]=i.\text{ Check its parity.}Counting times we’ve done that so that ∀i,a[i]=i. Check its parity.
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
int n;
int a[1000010];
int ans=0;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;++i)
scanf("%d",&a[i]);
for(int i=1;i<=n;++i)
while(a[i]!=i){
std::swap(a[i],a[a[i]]);
++ans;
}
if(ans%2==n%2) puts("Petr");
else puts("Um_nik");
}