CF1062B·Math

初见安~这里是传送门:CF #520 Div2 B Math

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

  • mul xx: multiplies nn by xx (where xx is an arbitrary positive integer).
  • sqrt: replaces nn 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 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.

Sol

看到样例2的解释后整个人都懵了——并不能乘一次,开一次方这么做啊!!!【看了题解才恍然大悟的我】

说一下思路——首先我们可以确定出最后的最小值,因为不管n为多少,最后剩下的数一定是质因子各一个的乘积。这个可以通过分解质因数来得到。

再者就是次数——因为我们知道目标状态【也就是最小值】,但是不知道起始状态【也就是乘了一些值过后开始开方时的值,先乘再开方是最省次数的】。所以我们就倒着找,从得到的最小值一直平方,直到为原数的整数倍。如果大于原数的话,那么次数才+1,用于乘法,否则不用,可以直接开方。

就这样【??!】真的很水。我承认真的很水。但是我就是没做起!!!没办法太蠢了。【理直气壮】

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x, tmp, ans = 1, num = 0;
int main() {
	scanf("%lld", &x);
	ll n = x;
	for(int i = 2; ; i++) {
		if(n == 1) break;
		if(n % i == 0) ans *= i;//分解质因数,最后同一种质因子一定只剩下一个。
		while(n % i == 0) n /= i;
	} 
	
	n = ans;
	while(n % x) n *= n, num++;//逆向还原
	if(n > x) num++;//用于乘法
	printf("%lld %lld\n", ans, num);
	return 0;
}

迎评:)
——End——

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值