Article From:https://www.cnblogs.com/mch5201314/p/9970306.html

Give you n, there are two operations, either multiply by a number, or open the root, but it must be an integer after the root, ask you what the minimum number is, and output the steps.

Detailed Link

[https://blog.csdn.net/Hackbuteer1/article/details/6681157]

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long 
ll a[100000];
ll log2(ll value)   //Recursively determine how many times a number is 2{If (value = 1)Return 0;ElseReturn 1 + log2 (value & gt; & gt; 1));}Int main () {Ll n, I;Ios:: sync_with_stdio (false);Cin. tie (0); cout. tie (0);While(cin & gt; & gt; n) {Ll c=0;Ll k=n;Ll b[1000];Int cnt=0;Int j=0;For (i = 2; I & lt; = n; I + +) {Cnt=0;While (n%i==0){A[c++]=i;N/=i;Cnt++;}If (cnt) B [j++] = cnt;Cnt=0;}Ll ans=1;A [c] = 1000007;For (i = 0; I & lt; c; I + +)If (a [i]!= a [i + 1])Ans = ans*a[i];Sort (B, b+j);Cnt=0;If (b [0]! = B [j-1])Cnt+=1;If (b [j-1]==1) {Cout & lt; & lt; K & lt; & lt;'& lt; & lt; 0 & lt; & lt; endl;Return 0;}Else if ((b [j-1] & amp; B [j-1]-1) === 0) {// judgement is the power of 2?Cout< ≪ ans & lt; & lt;'& lt; & lt; log2 (b [j-1]) +cnt & lt; & lt; endl;}ElseCout< <Ans & lt; & lt;'& lt; & lt; log2 (b [j-1]) +2 & lt; & lt; endl;}Return 0;}
Link of this Article: B. Math

Leave a Reply

Your email address will not be published. Required fields are marked *