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) ...
随机推荐
- Invalid bean definition with name 'dataSource' defined in class path resource [applicationContext.xml]
启动tomcat,访问一个web项目失败,查看日志,发现异常信息: 18-Jul-2019 15:22:16.822 严重 [main] org.apache.catalina.core.Standa ...
- 身边的人工智能&人工智能发展史
智能家具 扫地机器人 智能音箱 个人助手 在线翻译 谷歌翻译 微软翻译 YouTube 视频翻译 图像识别 人脸识别 AI+摄像头 下棋高手 Alphago 2017年打败柯洁 成为世界第一 Alph ...
- Codeforces 1299B/1300D - Aerodynamic
题目大意: 给定一个图形S,让这个图形任意平移,但是要保证原点(0,0)一直在它的内部或者边上 最后把它能移动到的所有位置进行拼合可以得到一个图形T 问图形S与图形T是否相似 点会按照逆时针顺序给出 ...
- Ubuntu hive 安装过程中遇到的一些问题
环境:Ubuntu14.04 Hadoop3.2.0 MySQL5.7 hive2.3.6 安装步骤:安装hive.MySQL并进行配置 安装过程参照:Ubuntu安装hive,并配置mysql作为元 ...
- 使用java(jdbc)向mysql中添加数据时出现“unknown column……”错误
错误情况如题,出现这个错误的原因是这样的: 在数据库中,插入一个字符串数据的时候是需要用单引号引起来的. 而下面的代码,注意看: sta.executeUpdate("INSERT INTO ...
- squid完全攻略
squid完全攻略 http://blog.sina.com.cn/s/blog_7572cf8e0100rl99.html squid,nginx,lighttpd反向代理的区别 [root@loc ...
- h5-携程页面小案例-伸缩盒子
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [kuangbin 带你飞] DP专题——HDU - 1024
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 深入分析Java反射(四)-动态代理
动态代理的简介 Java动态代理机制的出现,使得Java开发人员不用手工编写代理类,只要简单地指定一组接口及委托类对象,便能动态地获得代理类.代理类会负责将所有的方法调用分派到委托对象上反射执行,在分 ...
- Java--包密封
参考:http://blog.csdn.net/zhifeiyu2008/article/details/8829637 http://blog.csdn.net/technerd/article/ ...