Math(数论-分解素因子)

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 xx 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≤1061≤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 100100and then sqrt to get 1010.

In the second example, you can first apply sqrt to get 7272, then mul 1818to 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.

题意:输入一个数,可以对这个数进行两种操作:

           1.乘以任何一个数 x

           2.如果这个数为平方数(4,9,16,25…),可以对这个数开根号。

      求经过若干次操作后,这个数最小能变成哪个数?并输出最少的变换次数。

思路:  首先我们知道对于任何一个数都可以转换为:x=p1^a1 * p2 ^a2 * p3^a3 * ... * pn^an  (其中 pi 为素数)。

那么我们来考虑平方数的特性 例如:4 = 2^2;   9 = 3^2 ;   16 = 2^4;  25 = 5^2;  36 = 2^2 * 3^2; 

由此我们可以知道只要将这个数 素因子分解,得到的素因子的指数都为偶数时,这个数为平方数那么当所有的指数都为 1 时,此时这个数就是能够变换到最小的那个数了。也就是说,我们现在要求的仅仅是将所有指数都变为1的操作步数,当然每次都开根号肯定是最快的了,也就是求最少步数的办法那么第一步我们就需要先将所有的指数统一转换为 2^n ,这样才能够每次都是开根号,由于我们可以乘以任何一个数 x 。所以我们不需要管我们乘的是谁,只把指数转变成满足条件的最小的 2^n 即可,然后每次开根号,计算操作次数。

代码如下:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
#define LL long long
LL num[50010];
int book[1000010],p;
map<int,int>v;
void init() //打素数表
{
    p=0;
    for(int i=2; i<100010; i++)
    {
        if(!book[i])
        {
            num[p++]=(LL)i;
            for(int j=2*i; j<100010; j+=i)
                book[j]=1;
        }
    }
}
void work(LL &x,int &cnt)
{
    int maxx=1;
    LL z=1;//能够转换成的最小数
    for(int i=0; num[i]*num[i]<=x; i++) //分解素因数
    {
        if(x%num[i]==0)
        {
            int ans=0;
            while(x%num[i]==0)
            {
                x/=num[i];
                ans++;//指数的个数
            }
            z=z*num[i];//能够转换成的最小数
            maxx=max(maxx,ans);//最大指数
            v[ans]=1; //map去重,最后观察右多少个不同的指数
        }
    }
    if(x!=1)//没有除尽的话
    {
        z=z*x;
        v[1]=1;
    }
    x=z;
    cnt=0;
    if(maxx==1)return;//本身就是最小的

    LL s=1;//需要开多少次根号
    while(s<maxx)
    {
        cnt++;
        s<<=1;
    }
    if(s==maxx&&v.size()!=1)cnt++; //如果最大的指数就是2^n 但是其他指数不是2^n,因此第一步要乘以一个数
    else if(s!=maxx)cnt++;//如果最大的指数不是2^n, 因此第一步要乘以一个数

    return;
}
int main()
{
    LL n;
    init();
    scanf("%lld",&n);
    int ans;
    work(n,ans);
    printf("%lld %d\n",n,ans);
}

猜你喜欢

转载自blog.csdn.net/qq_41890797/article/details/84636201