D. Almost All Divisors
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.
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.
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.
2
8
8 2 12 6 4 24 16 3
1
2
48
4
题解:对于一个数,他所有的因子是对称分布的,最小的与最大的相乘就为该数,次小的与次大的相乘也为该数,依次类推,那么我们只要根据已知条件求得原来的数是多少,然后再判断该数的所有因子除了1和本身是否都在所给信息中存在并且除了1和本身它的因子个数也应等于给出来的n,判断输出即可。
#include<bits/stdc++.h>
using namespace std; typedef long long ll;
int main()
{
int T;
cin>>T;
while(T--){
int n;
cin>>n;
vector<ll>v;
for(int i=;i<=n;i++){
int x;
cin>>x;
v.push_back(x);
}
sort(v.begin(),v.end());
ll ans=v[]*v[v.size()-];
int sum=,flag=;
for(ll i=;i*i<=ans;i++){
if(ans%i==){
if(find(v.begin(),v.end(),i)==v.end()||find(v.begin(),v.end(),ans/i)==v.end()){flag=;break;}
sum+=;
if(i*i==ans)
sum--;
}
}
if(sum==n&&flag==)
cout<<ans<<endl;
else
cout<<-<<endl;
}
return ;
}
D. Almost All Divisors的更多相关文章
- codeforces 27E Number With The Given Amount Of Divisors
E. Number With The Given Amount Of Divisors time limit per test 2 seconds memory limit per test 256 ...
- HDU - The number of divisors(约数) about Humble Numbers
Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence ...
- Divisors
计算小于n的数中,约数个数最多的数,若有多个最输出最小的一个数. http://hihocoder.com/problemset/problem/1187 对于100有 60 = 2 * 2 * 3 ...
- Xenia and Divisors
Xenia and Divisors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- hihocoder1187 Divisors
传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given an integer n, for all integers not larger than n, f ...
- The number of divisors(约数) about Humble Numbers[HDU1492]
The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Lim ...
- Sum of divisors
Problem Description mmm is learning division, she's so proud of herself that she can figure out the ...
- Codeforces Beta Round #85 (Div. 1 Only) B. Petya and Divisors 暴力
B. Petya and Divisors Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/111 ...
- UVa 294 (因数的个数) Divisors
题意: 求区间[L, U]的正因数的个数. 分析: 有这样一条公式,将n分解为,则n的正因数的个数为 事先打好素数表,按照上面的公式统计出最大值即可. #include <cstdio> ...
- hdu4432 Sum of divisors(数论)
Sum of divisors Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
随机推荐
- js去除热点的虚线框
1.一个页面有多张图片,图片的链接为热点绘制,在ie中点击会出现虚线框. <script type="text/javascript"> window.onload = ...
- Sequence Models Week 1 Character level language model - Dinosaurus land
Character level language model - Dinosaurus land Welcome to Dinosaurus Island! 65 million years ago, ...
- OpenStack(四)——使用Kolla部署OpenStack多节点云
(1).实验环境 主机名 IP地址 角色 内存 网卡 CPU 磁盘 OpenStack-con 192.168.128.110 controller(控制) 8G 桥接网卡ens32和ens33 4核 ...
- Linux下mysql5.7安装
当前最新版本为5.7,此次将分别采用yum安装和tar包编译安装的方式分别说明. 一.Yum安装 A:获取repo源 [root@localhost ~]# wget http://dev.mysql ...
- 7206VXR系列板卡简介(转)
原文链接:https://www.it610.com/article/3116409.htm作者:hjw2011 ATM板卡介绍 板卡PA-A6-OC3MM,PA-A6-OC3SMI,PA-A6-OC ...
- 协程与异步IO
协 程 协程,又称微线程,纤程. 协程的优势: 协程的特点在于是一个线程执行. 协程的最大优势是极高的执行效率,因为子程序切换不是线程切换,而是由 ...
- 1月18日 LCA专项训练
A. Lorenzo Von Matterhorn B.Minimum spanning tree for each edge C.Misha, Grisha and Underground D.Fo ...
- hadoop cmd
一.hadoop文件操作 1.Ls hadoop fs -ls / 2.Put hadoop fs -put xx /path 3.Mkdir hadoop fs -mkdir 4.要从HDFS中删除 ...
- Docker MongoDB 集群搭建
简单地在Docker环境上搭建一个无认证的MongoDB集群.1.本文使用的容器集群角色 ContainerName IP:portConfig Server cfg_1 10.1.1.2:27 ...
- [LuoguP3978](https://www.luogu.org/problem/P3978) BZOJ4001概率论
BZOJ 4001 概率论 设\(f_i\)表示i个点的二叉树方案数 立刻有\(f_n = \sum_{i=0}^{n-1} f_i f_{n-i-1}\) 设\(F(x)为序列f的生成函数,有F(x ...