This question is to find the maximum number of power to which a number can be opened. This includes a negative number and must be read in long data. First, we break down the prime factor of this number and calculate their respective numbers. Then, we find a GCD for their numbers and finally output them. If it is a positive number, it is output directly. If it is a negative number, you need to find the largest Odd Factor.
The Code is as follows:
#include <cstdlib>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;int p[66000], cnt;long long rec[6600], N; int son[6600];int gcd(int a, int b){ return b == 0 ? a : gcd(b, a % b); }void pre(){ int k; for (int i = 4; i <= 66000; i += 2) { p[i] = 1; } for (int i = 3; i <= 257; i += 2) { if (!p[i]) { k = 2 * i; for (int j = i * i; j <= 66000; j += k) { p[j] = 1; } } } cnt = 1; rec[1] = 2; for (int i = 3; i <= 66000; i += 2) { if (!p[i]) { rec[++cnt] = i; } }// printf("cnt = %d\n", cnt);}int deal(long long x){ bool flag = true; int ans = 0; for (int i = 1; i <= cnt; ++i) { while (x % rec[i] == 0) { son[i]++; x /= rec[i]; } } if (x != 1) { return 1; } for (int i = 1; i <= cnt; ++i) { if (son[i]) { ans = gcd(ans, son[i]); } } return ans;}// 1728 = 12 ^ 3 11664 = 108^2int main(){ int ans; pre(); while (scanf("%I64d", &N), N) { memset(son, 0, sizeof (son)); ans = deal(N < 0 ? -N : N); if (N < 0) { while (!(ans & 1)) { ans >>= 1; } printf("%d\n", ans); } else { printf("%d\n", ans); } } return 0; }