---恢复内容开始---

We guessed some integer number xx. You are given a list of almost all its divisors. Almost all means that there are all divisors except 11and xx in the list.

Your task is to find the minimum possible integer xx that can be the guessed number, or say that the input data is contradictory and it is impossible to find such number.

You have to answer tt independent queries.

Input

The first line of the input contains one integer tt (1≤t≤251≤t≤25) — the number of queries. Then tt queries follow.

The first line of the query contains one integer nn (1≤n≤3001≤n≤300) — the number of divisors in the list.

The second line of the query contains nn integers d1,d2,…,dnd1,d2,…,dn (2≤di≤1062≤di≤106), where didi is the ii-th divisor of the guessed number. It is guaranteed that all values didi are distinct.

Output

For each query print the answer to it.

If the input data in the query is contradictory and it is impossible to find such number xx that the given list of divisors is the list of almost allits divisors, print -1. Otherwise print the minimum possible xx.

Example
input

Copy
2
8
8 2 12 6 4 24 16 3
1
2
output

Copy
48
4

思路:求出因子个数,看是否这n个数是否包含这n个因子数,然后判断一下再判断一下这n个数是否是他的因子

代码:

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<cmath>
const int maxn=1e5+;
typedef long long ll;
using namespace std;
ll count(ll n){
ll s=;
for(ll i=;i*i<=n;i++){
if(n%i==){
int a=;
while(n%i==){
n/=i;
a++;
}
s=s*(a+);
}
}
if(n>) s=s*;
return s;
}
ll a[maxn];
int main()
{
int T;
cin>>T;
int n;
while(T--)
{
scanf("%d",&n);
ll maxx=;
ll minn=;
ll x;
for(int t=;t<n;t++)
{
scanf("%lld",&a[t]);
maxx=max(a[t],maxx);
minn=min(a[t],minn);
}
ll ans=maxx*minn;
bool flag=false;
for(int t=;t<n;t++)
{
if(ans%a[t]!=)
{
flag=true;
}
}
if(count(ans)-==n&&flag==false)
printf("%lld\n",ans);
else
{
printf("-1\n");
} }
return ;
}

---恢复内容结束---

Almost All Divisors(求因子个数及思维)的更多相关文章

  1. Trailing Zeroes (I) LightOJ - 1028(求因子个数)

    题意: 给出一个N 求N有多少个别的进制的数有后导零 解析: 对于一个别的进制的数要转化为10进制 (我们暂且只分析二进制就好啦) An * 2^(n-1) + An-1 * 2^(n-2) + `` ...

  2. POJ 2992 Divisors (求因子个数)

    题意:给n和k,求组合C(n,k)的因子个数. 这道题,若一开始先预处理出C[i][j]的大小,再按普通方法枚举2~sqrt(C[i][j])来求解对应的因子个数,会TLE.所以得用别的方法. 在说方 ...

  3. LightOj1028 - Trailing Zeroes (I)---求因子个数

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1028 题意:给你一个数 n (1<=n<=10^12), 然后我们可以把它 ...

  4. Easy Number Challenge(暴力,求因子个数)

    Easy Number Challenge Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  5. HDU-1492-The number of divisors(约数) about Humble Numbers -求因子总数+唯一分解定理的变形

    A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence 1, 2, 3, 4, ...

  6. Divisors (求解组合数因子个数)【唯一分解定理】

    Divisors 题目链接(点击) Your task in this problem is to determine the number of divisors of Cnk. Just for ...

  7. BZOJ3994:约数个数和(莫比乌斯反演:求[1,N]*[1,M]的矩阵的因子个数)

    Description  设d(x)为x的约数个数,给定N.M,求   Input 输入文件包含多组测试数据. 第一行,一个整数T,表示测试数据的组数. 接下来的T行,每行两个整数N.M. Outpu ...

  8. POJ-2992 Divisors---组合数求因子数目

    题目链接: https://cn.vjudge.net/problem/POJ-2992 题目大意: 给出组合数Cnk,求出其因子个数,其中n,k不大于431,组合数的值在long long范围内 解 ...

  9. hdu 6069 Counting Divisors(求因子的个数)

    Counting Divisors Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Oth ...

随机推荐

  1. Requests接口测试库-官网快速上手

    Requests 一个发送HTTP请求的库基于urllib3,相比自带的库,提供了更高效简洁的可用方法,测试从业者用来做接口测试的一个好工具 文章内容均来自官网:https://requests.re ...

  2. phpredis 扩展之操作 Redis,记下来记下来!

    phpredis 是 redis 的 php 的一个扩展,效率是相当高有链表排序功能,对创建内存级的模块业务关系很有用 $redis = new Redis(); $redis->connect ...

  3. python6.3类的继承与多态

    class Animal(object): def __init__(self,color): self.color=color def eat(self): print("动物在吃!&qu ...

  4. (转)交叉编译lrzsz

    交叉编译lrzsz 2016-03-20 1. 系统环境: Distributor ID:    Ubuntu Description:    Ubuntu 14.04.1 LTS Release:  ...

  5. Java 基础 —— 注解 Annotation

    简介 Annotation 是从 JDK 5.0 引入的. 注解使得我们可以以编译器验证的格式存储程序的额外信息.注解可以生成描述符文件,甚至是新的类定义,并且有助于减轻编写"样板" ...

  6. 实践Kong for Kubernetes(K8S),kong最新2.1版本和kong-ingress-controller:0.9.1版本

    先决条件 Kubernetes集群:您可以使用Minikube或GKE集群.Kong与Kubernetes的所有发行版兼容. kubectl访问权限:您应该已经kubectl安装并配置为与Kubern ...

  7. hdfs学习(一)

    一.hdfs概述 介绍: 在现代的企业环境中,单机容量往往无法存储大量数据,需要跨机器存储.统一管理分布在集群上的文件系统称为分布式文件系统 .HDFS(Hadoop Distributed File ...

  8. PythonCrashCourse 第二章习题

    2.3 个性化消息:将用户的姓名存到一个变量中,并向该用户显示一条消息.显示的消息应非常简单,如"Hello Eric, would you like to learn some Pytho ...

  9. 基础知识、DOS命令

    一.信息安全 1.信息源认证   https 访问控制   ACL   :不能有非法软件驻留   :不能含有未授权的操作等 2.2017-OWASP-TOP5 注入  :失效的身份认证和回话配置 :跨 ...

  10. eclipse及idea使用问题记录(为了方便github同步,重新用Markdown写了一篇)

    使用eclipse或idea的时候会遇到各式各样的小问题,解决方案其实网上也大都搜得到,但是下次遇到的时候总是想不起来如何解决,还要花费时间再次查资料.所以以后把遇到的问题都记录一下. @ 目录 Ec ...