CF1062B Math 题解

版权声明:版权所有,转载请标明博文出处。 https://blog.csdn.net/HQG_AC/article/details/85621809

本题居然没有题解,我来写一篇

我们发现如果一个数 x x 的分解质因数结果中有一些因数的质数不为零,我们总能够通过乘再开根使得他变为零,但不可能消失

于是第一个答案就是该数的所有质因子的积 y y

对于第二问,我们也就是要求从 x x y y 的变化次数

我们发现只会有一次乘法,因为只需要一次乘法+多次开根就可以搞定

那我们只需要每次把 y y 平方一下,如果是 x x 的倍数的话就break

特判正好等于 x x 的情况

然后就做完了

#include <bits/stdc++.h>
using namespace std ;
#define rep(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define SZ(x) ((int)x.size())
typedef long long ll ;
typedef unsigned long long ull ;
typedef vector <int> vi ;
typedef pair <int, int> pii ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 100010 ;
const int iinf = INT_MAX ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }

ll n, tot, ans, tmp, num = 1 ;

int main() {
    scanf("%lld", &n) ; tot = n ;
    for (int i = 2; i <= n; i++) {
        if (tot % i == 0) {
            num *= i ;
            while (tot % i == 0) tot /= i ;
        }
    }
    ll ans = 0, tmp = num ;
    while (num % n) {
        num *= num ;
        ans++ ;
    }
    printf("%lld %lld\n", tmp, num > n ? ans + 1 : ans) ;
}

猜你喜欢

转载自blog.csdn.net/HQG_AC/article/details/85621809
今日推荐