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) ...
随机推荐
- 【转】centos7轻松搭建文件服务器
1.安装apache服务器 yum install httpd 2:启动httpd服务 service httpd start 3:查看httpd服务器的版本 4:修改访问端口和文件路径,以防端口冲突 ...
- html_位置偏移属性position
定位属性 位置属性position:static.relative.absolute.fixed 偏移属性:top.bottom.left.right 浮动定位属性:float/clear 1.浮动定 ...
- HTML-基础标记
HTML, 一种超文本标记语言,顾名思义,要比文本的样式多,而且是由标记组成,还是一门语言. 标记写法 <标记名> <a></a>双标记 超链接 <br /& ...
- SSM框架和微服务构架和的联系与区别
spring和springMvc: 1. spring是一个一站式的轻量级的java开发框架,核心是控制反转(IOC)和面向切面(AOP),针对于开发的WEB层(springMvc).业务层(Ioc) ...
- 吴裕雄--天生自然 JAVASCRIPT开发学习:函数参数
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- STM32F407读编码器没上拉电阻遇见的问题
在调试之前由于本科阶段参加飞思卡尔智能汽车的竞赛,一直在使用与竞赛相关的单片机和编码器,后来由于工程的需要开始使用STM32的板子,在调试编码器的时候遇见了,使用了STM32的官方标准库中的定时器正交 ...
- 精讲 使用ELK堆栈部署Kafka
使用ELK堆栈部署Kafka 通过优锐课的java架构学习分享,在本文中,我将展示如何使用ELK Stack和Kafka部署建立弹性数据管道所需的所有组件. 在发生生产事件后,恰恰在你最需要它们时,日 ...
- CSS中的 position与Grid Layout
[1]CSS之Position(定位布局): 现css常用的属性有5种: 1.static 2.absolute 3.fixed 4.relative 5.sticky. 1.static 表示元素的 ...
- javaweb学习——会话技术(一)
会话: 1.什么是会话:从打开一个浏览器,访问页面,到最终关闭浏览器的一个过程,就是一次会话. 2.会话的特点:包含多个请求,一次完整的会话是只针对一个用户. 3.会话机制:web中常用的技术,用来跟 ...
- [浅学]POST、GET、PUT、DELETE 请求
HTTP定义了与服务器交互的不同的方法,最基本的是POST.GET.PUT.DELETE,与其比不可少的URL的全称是资源描述符,我们可以这样理解: url描述了一个网络上资源,而post.get.p ...