# Codeforces Round #520 (Div. 2) B. Math

B. Math

time limit per test：1 second
memory limit per test：256 megabytes

Description:

JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer

• mul
• sqrt: replaces

You can perform these operations as many times as you like. What is the minimum value of

Apparently, no one in the class knows the answer to this problem, maybe you can help them?

Input:

The only line of the input contains a single integer

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

typedef long long LL ;
const int N = 1e6+5;
int tot,n;
int u[N],prim[N],vis[N],a[N];

int main(){
scanf("%d",&n);
for(int i=2;i<=sqrt(n);i++){
for(int j=i*i;j<=n;j+=i){
if(!vis[j]) vis[j]=1;
}
}
for(int i=2;i<=n;i++) if(!vis[i]) prim[++tot]=i;
int tmp = n,cnt=1;
while(tmp>1){
if(tmp%prim[cnt]==0){
tmp/=prim[cnt];
a[prim[cnt]]++;
}else{
cnt++;
}
}
int maxn = 1;
cnt=0;
LL ans = 1,f = 1;
bool flag=false;
for(int i=2;i<=n;i++) if(a[i]){
maxn=max(maxn,a[i]),ans*=i;
}
for(int i=2;i<=n;i++){
if(a[i]&&a[i]!=maxn) flag=true ;
}
while(1){
if(f>=maxn){
if(flag) break ;
if(f==maxn) flag=false;else flag=true;
break;
}
f*=2;
cnt++;
}
printf("%lld %d",ans,cnt+(flag==true));
return 0;
}
View Code

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int n,cnt,ans=1;
vector <int > vec ;

int main(){
scanf("%d",&n);
int maxn = 0;
for(int i=2;i<=n;i++){
cnt = 0;
if(n%i==0) ans*=i;
while(n%i==0){
n/=i;
cnt++;
}
while(1<<(maxn)<cnt) maxn++;
if(cnt) vec.push_back(cnt);
}
int flag = 0;
for(int i=0;i<vec.size();i++){
if(vec[i]!=(1<<maxn)) flag=1;
}
printf("%d %d",ans,flag+maxn);
return 0;
}
View Code

posted @ 2018-11-19 22:45  heyuhhh  阅读(375)  评论(0编辑  收藏  举报