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
思路:求出因子个数,看是否这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(求因子个数及思维)的更多相关文章
- Trailing Zeroes (I) LightOJ - 1028(求因子个数)
题意: 给出一个N 求N有多少个别的进制的数有后导零 解析: 对于一个别的进制的数要转化为10进制 (我们暂且只分析二进制就好啦) An * 2^(n-1) + An-1 * 2^(n-2) + `` ...
- POJ 2992 Divisors (求因子个数)
题意:给n和k,求组合C(n,k)的因子个数. 这道题,若一开始先预处理出C[i][j]的大小,再按普通方法枚举2~sqrt(C[i][j])来求解对应的因子个数,会TLE.所以得用别的方法. 在说方 ...
- LightOj1028 - Trailing Zeroes (I)---求因子个数
题目链接:http://lightoj.com/volume_showproblem.php?problem=1028 题意:给你一个数 n (1<=n<=10^12), 然后我们可以把它 ...
- Easy Number Challenge(暴力,求因子个数)
Easy Number Challenge Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
- 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, ...
- Divisors (求解组合数因子个数)【唯一分解定理】
Divisors 题目链接(点击) Your task in this problem is to determine the number of divisors of Cnk. Just for ...
- BZOJ3994:约数个数和(莫比乌斯反演:求[1,N]*[1,M]的矩阵的因子个数)
Description 设d(x)为x的约数个数,给定N.M,求 Input 输入文件包含多组测试数据. 第一行,一个整数T,表示测试数据的组数. 接下来的T行,每行两个整数N.M. Outpu ...
- POJ-2992 Divisors---组合数求因子数目
题目链接: https://cn.vjudge.net/problem/POJ-2992 题目大意: 给出组合数Cnk,求出其因子个数,其中n,k不大于431,组合数的值在long long范围内 解 ...
- hdu 6069 Counting Divisors(求因子的个数)
Counting Divisors Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Oth ...
随机推荐
- 实验03——java十进制转二、八、十六进制;打印'中'的十六进制;进制转换的api
package cn.tedu.demo; /** * @author 赵瑞鑫 E-mail:1922250303@qq.com * @version 创建时间:2020年7月16日 上午10:22: ...
- 使用Azure人脸API对图片进行人脸识别
人脸识别是人工智能机器学习比较成熟的一个领域.人脸识别已经应用到了很多生产场景.比如生物认证,人脸考勤,人流监控等场景.对于很多中小功能由于技术门槛问题很难自己实现人脸识别的算法.Azure人脸API ...
- office2010的破解工具
office2010的破解工具,找了好多的密钥都不合适,直接用这个软件一键搞定, 下载地址:https://pan.baidu.com/s/1phPwihCDipGwGdSmjWNeYw 提取码:8m ...
- Java日志框架(一)
在项目开发过程中,我们可以通过 debug 查找问题.而在线上环境我们查找问题只能通过打印日志的方式查找问题.因此对于一个项目而言,日志记录是一个非常重要的问题.因此,如何选择一个合适的日志记录框架也 ...
- NIO(二):Channel通道
一.Channel概述 channel(通道):进行IO的连接通道,为NIO的几个核心(Buffer,selector,channel)之一,相比于IO的stream具有较高的性能. IO 单向传输 ...
- 字段解析之OopMapBlock(4)
OopMapBlock是一个简单的内嵌在Klass里面的数据结构,用来描述oop中包含的引用类型属性,即该oop所引用的其他oop在oop中的内存分布,然后就可以根据当前oop的地址找到所有引用的其他 ...
- SpringBoot进阶教程(六十三)Jasypt配置文件加密
数据库密码直接明文写在配置中,对安全来说,是一个很大的挑战.一旦密码泄漏,将会带来很大的安全隐患.尤其在一些企业对安全性要求很高,因此我们就考虑如何对密码进行加密.本文着重介绍Jasypt对Sprin ...
- Elasticsearch第一篇:在 Windows 上的环境搭建
本文介绍如何在 windows 10 ,64位操作系统上安装最新版本 Elasticsearch.以及相关插件.之前看了不少园友的文章,用到的版本都比较低,尤其是插件的版本要和ES的版本相对应等这些问 ...
- 几个递进的make file
春节在家写的几个递进的make file,部分有点问题.接下来 有空我要把GNU make的手册看完.不然这方面太菜了. GNU make手册 都需要make先设置环境变量BUILD_MODE为run ...
- 性能测试必备知识(11)- 怎么理解内存中的Buffer和Cache?
做性能测试的必备知识系列,可以看下面链接的文章哦 https://www.cnblogs.com/poloyy/category/1806772.html 缓存 从 free 命令可以看到,缓存其实就 ...