Math

1012 篇文章 45 订阅

https://codeforces.com/contest/1062/problem/B

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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 nn, you can perform the following operations zero or more times:

  • mul x: multiplies nn by x (where x is an arbitrary positive integer).
  • sqrt: replaces n with n−−√n (to apply this operation, n−−√n must be an integer).

You can perform these operations as many times as you like. What is the minimum value of nn, that can be achieved and what is the minimum number of operations, to achieve that minimum value?

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 nn (1≤n≤106) — the initial number.

Output

Print two integers: the minimum integer nn that can be achieved using the described operations and the minimum number of operations required.

Examples

input

20

output

10 2

input

5184

output

6 4

Note

In the first example, you can apply the operation mul 55 to get 100100 and then sqrt to get 1010.

In the second example, you can first apply sqrt to get 7272, then mul 1818 to get 12961296 and finally two more sqrt and you get 66.

Note, that even if the initial value of nn is less or equal 106106, it can still become greater than 106106 after applying one or more operations.

题解:

By factorizing n we get n=p1a1p2a2…pkak (k is the number of prime factors). Because we can't get rid of those prime factors then the smallest nn is p1p2…pk. For each ai, let ui be the positive integer so that 2ui≥ai>2ui−1. Let U be max(ui). It's clear that we have to apply the "sqrt" operation at least U times, since each time we apply it, aiai is divided by 2 for all i. If for all ii, ai=2U then the answer is U, obviously. Otherwise, we need to use the operation "mul" 1 time to make all the ai equal 2U and by now the answer is U+1.

#include <iostream>
#include <stdio.h>
#include <map>
#include <math.h>
using namespace std;
int n;
int a[1000000+10];
map<int,int>m;
bool prime(int x){
    if(n==1)    return 0;
    if(n==2)    return 1;
    for(int i=2;i<=(int)sqrt(x);i++)
        if(x%i==0) return 0;
    return 1;

}
int main()
{

    scanf("%d",&n);
    if(prime(n)){
        cout << n <<" "<< 0 << endl;
    }else{

        int maxl=0,flag=0,ans=1,cnt;
        for(int i=2;i<n;i++){
            if(n%i==0&&prime(i)){
                ans*=i;
                while(n%i==0){
                    m[i]++;
                    n/=i;
                }
                if(maxl!=m[i]&&maxl!=0)
                    flag=1;
                maxl=max(maxl,m[i]);
            }
            if(prime(n)){
                ans*=n;
                m[n]++;
                if(maxl!=m[n]&&maxl!=0)
                    flag=1;
                maxl=max(maxl,m[n]);
                break;
            }
        }
        for(int i=0;i<=20;i++){
            int p=pow(2.0,i);
            if(p==maxl){
                cnt=i;
                if(flag)
                    cnt++;
                break;
            }
            if(p<maxl&&maxl<2*p){
                cnt=i+2;
                break;
            }
        }

        cout << ans <<" "<< cnt << endl;
    }

    // << "Hello world!" << endl;
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Starzkg

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值