C. Strongly Composite

文章描述了一个数学问题,给定一个整数数组,要求找出一个满足条件的新数组:新数组的元素是原数组元素乘积的因数且是大于1的强合数,且新数组的大小最大化。对于每个测试用例,输出满足条件的新数组的最大可能大小。示例和解题思路提供了具体的例子和方法。
摘要由CSDN通过智能技术生成

A prime number is an integer greater than 11, which has exactly two divisors. For example, 77 is a prime, since it has two divisors {1,7}{1,7}. A composite number is an integer greater than 11, which has more than two different divisors.

Note that the integer 11 is neither prime nor composite.

Let's look at some composite number vv. It has several divisors: some divisors are prime, others are composite themselves. If the number of prime divisors of vv is less or equal to the number of composite divisors, let's name vv as strongly composite.

For example, number 1212 has 66 divisors: {1,2,3,4,6,12}{1,2,3,4,6,12}, two divisors 22 and 33 are prime, while three divisors 44, 66 and 1212 are composite. So, 1212 is strongly composite. Other examples of strongly composite numbers are 44, 88, 99, 1616 and so on.

On the other side, divisors of 1515 are {1,3,5,15}{1,3,5,15}: 33 and 55 are prime, 1515 is composite. So, 1515 is not a strongly composite. Other examples are: 22, 33, 55, 66, 77, 1010 and so on.

You are given nn integers a1,a2,…,ana1,a2,…,an (ai>1ai>1). You have to build an array b1,b2,…,bkb1,b2,…,bk such that following conditions are satisfied:

  • Product of all elements of array aa is equal to product of all elements of array bb: a1⋅a2⋅…⋅an=b1⋅b2⋅…⋅bka1⋅a2⋅…⋅an=b1⋅b2⋅…⋅bk;
  • All elements of array bb are integers greater than 11 and strongly composite;
  • The size kk of array bb is the maximum possible.

Find the size kk of array bb, or report, that there is no array bb satisfying the conditions.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤10001≤t≤1000). The description of the test cases follows.

The first line of each test case contains one integer nn (1≤n≤10001≤n≤1000) — the size of the array aa.

The second line of each test case contains nn integer a1,a2,…ana1,a2,…an (2≤ai≤1072≤ai≤107) — the array aa itself.

It is guaranteed that the sum of nn over all test cases does not exceed 10001000.

Output

For each test case, print the size kk of array bb, or 00, if there is no array bb satisfying the conditions.

Example

input

Copy

8

2

3 6

3

3 4 5

2

2 3

3

3 10 14

2

25 30

1

1080

9

3 3 3 5 5 5 7 7 7

20

12 15 2 2 2 2 2 3 3 3 17 21 21 21 30 6 6 33 31 39

output

Copy

1
1
0
2
2
3
4
15

Note

In the first test case, we can get array b=[18]b=[18]: a1⋅a2=18=b1a1⋅a2=18=b1; 1818 is strongly composite number.

In the second test case, we can get array b=[60]b=[60]: a1⋅a2⋅a3=60=b1a1⋅a2⋅a3=60=b1; 6060 is strongly composite number.

In the third test case, there is no array bb satisfying the conditions.

In the fourth test case, we can get array b=[4,105]b=[4,105]: a1⋅a2⋅a3=420=b1⋅b2a1⋅a2⋅a3=420=b1⋅b2; 44 and 105105 are strongly composite numbers.

思路:

我们都知道,一个合数都可以分成有限个质数的乘积

题目strongly composite就是这个数因子中质数的个数小于等于合数的个数

给定一串数组 我们把其中的合数分解成尽可能小的质数

用一个map去储存个数数出现的个数

下面就拿一个数组去举例把

因为k要尽可能大而且bi又是可以分解出质数的合数,所以bi肯定由分解出的某一个质数组成

如果两个相同的质数相乘比如2*2 他们因子就是[1,2,4]strongly composite

如果两个不同的质数2*3  [1,2,3,6]不符合

那三个不同的质数呢 2*3*7  [1,2,3,7,2*3,2*7,3*7,2*3*7]符合

k要尽可能的小

所以一定要先把相同的变成一个b然后再考虑不相同的

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<vector>//res.erase(unique(res.begin(), res.end()), res.end())
#include<queue>
#include<stack>
#include<map>
#include<set>//iterator,insert(),erase(),lower/upper_bound(value)/find()return end()
#define int long long
using namespace std;
signed main(){
	int t;
	cin>>t;
	while(t--){
		map<int,int>mp;
		int n;
		cin>>n;
		for(int i=0;i<n;i++){
			int temp;
			cin>>temp;
			for(int j=2;j*j<=temp;j++){
				while(temp%j==0){
					temp=temp/j;
					mp[j]++;
				}
			}
			if(temp!=1){
				mp[temp]++;
			}
		}
		int sum1=0,sum2=0;
		for(auto q:mp){
			sum1+=q.second/2;
			sum2+=q.second%2;
		}
		cout<<sum1+sum2/3<<endl;
	}
} 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值