质因数分解

玄妙

题目

Dr. Mob has just discovered a Deathly Bacteria. He named it RC-01. RC-01 has a very strange reproduction system. RC-01 lives exactly x days. Now RC-01 produces exactly p new deadly Bacteria where x = bp (where b, p are integers). More generally, x is a perfect pth power. Given the lifetime x of a mother RC-01 you are to determine the maximum number of new RC-01 which can be produced by the mother RC-01.

Input
Input starts with an integer T (≤ 50), denoting the number of test cases.

Each case starts with a line containing an integer x. You can assume that x will have magnitude at least 2 and be within the range of a 32 bit signed integer.

Output
For each case, print the case number and the largest integer p such that x is a perfect pth power.

Sample Input
3
17
1073741824
25
Sample Output
Case 1: 1
Case 2: 30
Case 3: 2

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{	int t,num = 1;
	cin >> t;
	while(t--)
	{
		long long n;
		cin >> n;
		int flag = 0;
		if(n < 0)
		{
			n = -n;
			flag = 1;
			
		}
		int gcd = 0;
		for(long long i = 2;i * i <= n;i++)
		{
			int x = 0;
			if(n % i == 0)
			{
				while(n % i ==0)
				{
					x ++;
					n /= i;
				}
			}
			if(gcd == 0)
			gcd = x;
			else
			gcd = __gcd(x,gcd);
		}
		if(n > 1)
		gcd = __gcd(gcd,1);
		if(flag)
		{
			while(gcd % 2 == 0)
			{
				gcd /= 2;
			}
		}
	cout << "Case " << num++ << ": " << gcd << endl;	
	}
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值