CFround520B.Math,你数学学得咋样啊

今天晚上

数学场
真刺激

我都这么自闭了,还不放过我

本来以为这么难嘛大家肯定都写不来

眼看着大佬们一题一题的过,包括这道

磨人的B题

我想

还是先写C吧

....

嘿!巧了

哥德巴赫猜想!

当年我上高中的时候要是证出来了

那...

对8起

开个玩笑

我想

我搞懂了
一些莫名其妙/乱七八糟的套路
如果E题写出来了
那该有多好
但是猜了个错误的结论,也懒得说了

d题就是,那个题,点进去,扫了一眼,颤抖着点了出来...嗯.嗯~ o(* ̄▽ ̄*)o

来上题吧!虽然是CFB题,但是有点内什么的题
我拒绝
但还是要写

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

mul x: multiplies n by x (where x is an arbitrary positive integer).
sqrt: replaces n with n−−√ (to apply this operation, n−−√ must be an integer).
You can perform these operations as many times as you like. What is the minimum value of n, 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 n (1≤n≤106) — the initial number.

Output
Print two integers: the minimum integer n 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 5 to get 100 and then sqrt to get 10.

In the second example, you can first apply sqrt to get 72, then mul 18 to get 1296 and finally two more sqrt and you get 6.

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

show me the code!!!

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 const int N=1e7;
 5 int book[N];//records of primes//NO!!;
 6 int ans=1,flag;
 7 int cnt,m,num;//count,max!!!!!!!!!!,book der count~~~ 9 int main()
10 {
11     ios_base::sync_with_stdio(0);
12     cin.tie(0);
13     cout.tie(0);
14     int n;cin>>n;
15 
16     for(int i=2;i<=n;i++){
17         cnt=0;
18         if(n%i==0)ans*=i;
19         while(n%i==0){
20             n/=i;
21             cnt++;//记次数!!这个是出现次数,可能是2的几次方,也可能不是,等会儿会判断
22         }
23         while(1<<m<cnt)m++;//!!这步很重要
24         if(cnt)book[num++]=cnt;
25     }
26 
27     for(int i=0;i<num;i++){//最多乘一次呀~~~
28         if(book[i]!=(1<<m)){
29             cout<<ans<<" "<<1+m;
30             return 0;
31         }
32     }
33     cout<<ans<<" "<<m;
34 
35 // for(int i=2;i<n;i++){
36        // if(book[i]>=1&&book[i]<<x)
37             //cnt=max(cnt,)呸呸呸!!!!!
38 
39     return 0;
40 }

这题很容易看出来,就是求各个质因数的集合,并且把他们出现的次数求出一个sqrt的最大次数m,

最小的那个数,就是各个质因数的乘积

乘法操作顶多一次,用来把那些平方不了的数们拯救出来~~;(LINE27-LINE31,用于判断)

具体实现搞了好久,老是出错,主要是注意循环的里面的顺序~

还有几个小点:

就是这个m怎么求,以及,是否进行乘法操作的判断条件是什么?

因为是sqrt,所以要判断那个质因数的出现次数是不是小于2的m次方,如果它大于,那么m被更新了,这是m的求法

接下来就是第27-31行,如果我们记录下来的所有质因数的出现次数是不是均为2的几次方,如果是的话,那么乘法操作就不用了,直接开方,开m次就行了,如果不是,那么肯定要有一次乘法作为补充~

ok~结束了!!

去看看E题吧

感觉有点

不怕死

啥题都敢硬上

E题啊大姐(可惜公式都猜了)

猜你喜欢

转载自www.cnblogs.com/guaguastandup/p/10340165.html