# 2019 Multi-University Training Contest 4

http://acm.hdu.edu.cn/contests/contest_show.php?cid=851

## 1001. AND Minimum Spanning Tree

#include<bits/stdc++.h>
using namespace std;

x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int sta[maxn],ans;

void solve() {
for(int i=2;i<=n;i++) {
int bo=-1;
for(int j=0;(1<<j)<=i;j++)
if(!(i&(1<<j))) {bo=j;break;}
if(bo==-1) sta[i]=n==i?1:i+1,ans+=n==i;
else sta[i]=1<<bo;
}write(ans);
for(int i=2;i<=n;i++) printf("%d%c",sta[i],i==n?'\n':' ');
}

int main() {
return 0;
}


## 1008. K-th Closest Distance

#include<bits/stdc++.h>
using namespace std;

x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

int rt[maxn];

struct chairman_tree {
int ls[maxn*40],rs[maxn*40],s[maxn*40],seg;

void modify(int &p,int pre,int l,int r,int x) {
p=++seg;ls[p]=ls[pre],rs[p]=rs[pre],s[p]=s[pre]+1;
if(l==r) return ;int mid=(l+r)>>1;
if(x<=mid) modify(ls[p],ls[pre],l,mid,x);
else modify(rs[p],rs[pre],mid+1,r,x);
}

int query(int a,int b,int l,int r,int x,int y) {
if(x<=l&&r<=y) return s[b]-s[a];
int mid=(l+r)>>1,ans=0;
if(x<=mid) ans+=query(ls[a],ls[b],l,mid,x,y);
if(y>mid) ans+=query(rs[a],rs[b],mid+1,r,x,y);
return ans;
}

void clear() {
for(int i=1;i<=seg;i++) s[i]=ls[i]=rs[i]=0;
}
}T;

int n;

void solve() {
for(int i=1;i<=m;i++) {
l^=la,r^=la,p^=la,k^=la;
int L=0,R=1e6;
while(L<=R) {
int mid=(L+R)>>1;
if(T.query(rt[l-1],rt[r],1,1e6,max(1,p-mid),min((int)1e6,p+mid))>=k) R=mid-1,la=mid;
else L=mid+1;
}write(la);
}
}

void clear() {
for(int i=1;i<=n;i++) rt[i]=0;
T.clear();
}

int main() {
return 0;
}


## 1010. Minimal Power of Prime

#include<bits/stdc++.h>
using namespace std;

#define int long long

x=0;int f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
if(x<0) putchar('-'),x=-x;
if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;
const int B = 5000;

int pri[maxn],tot,vis[maxn];

void sieve() {
for(int i=2;i<=B;i++) {
if(!vis[i]) pri[++tot]=i;
for(int j=1;j<=tot&&i*pri[j]<=B;j++) {
vis[i*pri[j]]=1;
if(i%pri[j]==0) break;
}
}
}

void solve() {
for(int i=1;i<=tot;i++) {
if(n%pri[i]) continue;
int tmp=0;
while(n%pri[i]==0) tmp++,n/=pri[i];
ans=min(ans,tmp);
}if(ans==1||n==1) {write(ans);return ;}
for(int i=4;i>=2;i--) {
int x=pow(n,1.0/i);
for(int j=max(x-10,0ll);j<=x+10;j++)
if(pow(j,i)==n) {write(min(ans,i));return ;}
}write(1);
}

signed main() {
sieve();