Linux   发布时间:2022-04-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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 mini

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

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 Integexx 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 Integett (1t251≤t≤25) — the number of queries. Then tt queries follow.

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

The second line of the query contains @H_874_186@nIntegers @H_517_197@d1,@H_197_200@d2,,dnd1,d2,…,dn (2di1062≤di≤106),where @H_197_253@didi is the @H_450_264@ii-th divisor of the guessed number. it is guaranteed that all values @H_772_276@didi ardisTinct.

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+5;
typedef long long ll;
using namespace std;
ll count(ll n){
    ll s=1;
    for(ll i=2;i*i<=n;i++){
        if(n%i==0){
            int a=0;
            while(n%i==0){
                n/=i;
                a++;
            }
            s=s*(a+1);
        }
    }
    if(n>1) s=s*2;
    return s;
}
ll a[maxn];
int main()
{
   int T;
   cin>>T;
   int n;
   while(T--)
   {
       scanf("%d",&n);
       ll maxx=2;
       ll minn=10000000;
       ll x;
       for(int t=0;t<n;t++)
       {
           scanf("%lld",&a[t]);
           maxx=@H_709_378@max(a[t],maxX);
           minn=@H_709_378@min(a[t],minn);
    }
    ll ans=maxx*@H_709_378@minn;
    bool flag=false;
    for(int t=0;t<n;t++)
    {
        if(ans%a[t]!=0)
        {
            flag=true;
        }
    }
    if(count(ans)-2==n&&flag==false)
    printf("%lld\n",ans);
    else
    {
        printf("-1\n");
    }
    

   }
   return 0;
}

 

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

大佬总结

以上是大佬教程为你收集整理的Almost All Divisors(求因子个数及思维)全部内容,希望文章能够帮你解决Almost All Divisors(求因子个数及思维)所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。