https://codeforces.com/contest/1165/problem/D

题解:给定的数组是答案的除1和本身以外所有因子,求答案

题解:贪心

答案=最大值*最小值

因子可能有多或者少;

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
#define endl "\n"
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=100000+10;
const int M=100000+10;
const int MOD=1e9+7;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,p,l,r,u,v;
ll ans,cnt,flag,temp,sum;
ll a[N];
char str;
struct node{};
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endif//ios::sync_with_stdio(false);//cin.tie(0);//cout.tie(0);scanf("%d",&t);while(t--){scanf("%d",&n);ll maxl=-INF;ll minl=INF;for(int i=1;i<=n;i++){scanf("%I64d",&a[i]);maxl=max(a[i],maxl);minl=min(a[i],minl);}ans=maxl*minl;sort(a+1,a+n+1);int sqr=sqrt(ans);cnt=0;for(int i=2;i<=sqr;i++){if(ans%i==0){int x=lower_bound(a+1,a+n+1,ans/i)-a;int y=lower_bound(a+1,a+n+1,i)-a;//cout<<x<<endl;if(x>n||x<1||y>n||y<1||a[x]!=ans/i||a[y]!=i){ans=-1;break;}cnt++;if((ll)i*i!=ans){cnt++;}}}cout<<(cnt==n?ans:-1)<<endl;}#ifdef DEBUGprintf("Time cost : %lf s\n",(double)clock()/CLOCKS_PER_SEC);
#endif//cout << "Hello world!" << endl;return 0;
}

Almost All Divisors相关推荐

  1. 【Project Euler】530 GCD of Divisors 莫比乌斯反演

    [题目]GCD of Divisors [题意]给定f(n)=Σd|n gcd(d,n/d)的前缀和F(n),n=10^15. [算法]莫比乌斯反演 [题解]参考:任之洲数论函数.pdf 这个范围显然 ...

  2. UVA 294 - Divisors (唯一分解)

    题目链接 https://cn.vjudge.net/problem/UVA-294 [题意] 输入两个整数L,R(1<=L,R<=1e9,U-L<=10000)统计区间 [L,U] ...

  3. C++ number of positive divisors计算正除数的实现算法(附完整源码)

    C++number of positive divisors计算正除数的实现算法 C++number of positive divisors计算正除数的实现算法完整源码(定义,实现,main函数测试 ...

  4. HDU 1492 The number of divisors(约数) about Humble Numbers(数论,简单约数)

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

  5. Number With The Given Amount Of Divisors(反素数)

    Given the number n, find the smallest positive integer which has exactly n divisors. It is guarantee ...

  6. Codeforces Round #726 (Div. 2) D. Deleting Divisors 博弈

    传送门 文章目录 题意: 思路: 题意: 给你一个数nnn,有两个人博弈,每次可以将nnn减去一个nnn的因子,这个因子不能为111或nnn.当不能操作的人输掉游戏.问你先手赢还是后手赢. 思路: 这 ...

  7. uva 294 ——Divisors

    题意:给定一个区间[l,r],然后问在该区间内谁的因子最多! 思路:先大致分析一下,比如对于一个数12,那么可以拆分成2*2*3,就是对一个数分解质因数,然后你会发现在组成因子的时候,每个质因数可以选 ...

  8. 【CodeForces - 27E】Number With The Given Amount Of Divisors (数论,数学,反素数)

    题干: Given the number n, find the smallest positive integer which has exactly n divisors. It is guara ...

  9. HDU 1492 The number of divisors(约数) about Humble Numbers

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...

  10. HDUOJ---The number of divisors(约数) about Humble Numbers

    The number of divisors(约数) about Humble Numbers Time Limit: 2000/1000 MS (Java/Others)    Memory Lim ...

最新文章

  1. 解析并符号 读取dll_Spring IOC容器之XmlBeanFactory启动流程分析和源码解析
  2. php四位数加密,如何使用php实现一个对数字进行8位的加密解密函数
  3. SpringBoot中在普通类里面加载Spring容器中的类
  4. CentOS 6.5 伪分布安装
  5. 爬虫为什么用Chrome?
  6. 【深度学习】你不知道的车牌识别系统
  7. 待字闺中:日志查询。(网络摘要)
  8. 下一代CC++测试框架TestNG++入门指导【转】
  9. python --- 线程
  10. C语言程序设计答案黄保和编,C语言程序设计答案(黄保和编)第5章.pdf
  11. java学习(135):map中泛型使用
  12. python中单下划线(_)和双下划线(__)的特殊用法 还等什么
  13. 从零起步到Linux运维经理,你必须管好的23个细节
  14. FreeMarker MyEclipse IDE
  15. 尔雅 2017大学计算机基础答案,2018超星尔雅大学计算机基础答案
  16. 四川大学计算机学院2020推免公示,2020四川大学计算机学院推免夏令营通知
  17. 手机地图导航哪个好?手机导航地图推荐
  18. 互联网产品经理面试问题汇总(18问)
  19. Android WiFi功能实现,知其然必知其所以然!(一)
  20. 神经网络中的偏置值什么意思

热门文章

  1. keep alive PHP,vue中keep-alive使用方法详解
  2. python 下载公众号文章_python3下载公众号历史文章
  3. 怎么设置qq信息同步服务器,QQ输入法如何设置网络同步
  4. 最java大子矩阵和问题_最大子矩阵问题实例解析
  5. 没学c语言可以学python_学了Python,但是没有学c,直接去学c++是可行的吗?
  6. java向另一activity输入_Android中调用另一个Activity并返回结果-以模拟选择头像功能为例...
  7. js中while死循环语句_Java系列教程day06——循环语句
  8. android开发标签栏应该设置多少钱,android – Flutter:刷卡后默认标签栏控制器......
  9. mysql 存储过程 select 循环_简简单单储存过程——循环一个select结果集
  10. 区块链分叉如何解决_什么是分叉区块链又该如何分叉