The Factor HDU - 5428(数论)

编程入门 行业动态 更新时间:2024-10-26 00:28:01

The Factor HDU - 5428(<a href=https://www.elefans.com/category/jswz/34/1769432.html style=数论)"/>

The Factor HDU - 5428(数论)

The Factor HDU - 5428(分解质因数)

传送门
题目大意:
输入一个序列,求他们所有数的乘积,然后找到最后的这个数的能整除它的最小因子。条件限制,这个最小因子必须满足有两个以上的数能整除它,包括它自己。数据范围 1—2e9

众所周知(口胡开始),一个数能分解为若干个质数相乘(1除外),这道题把序列的每个数分解为最小质因数,用数组存起来,最后排个序,把前两个相乘即可,如果数组长度为一,输出“-1”,即不成立

#include <iostream>
#include <cstdio>
#include<cstdlib>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include<time.h>
#include <stack>
#include <list>
#include <set>
#include <sstream>
#include <iterator>
using namespace std;
#define FOPI freopen("input.in", "r", stdin)
#define DOPI freopen("output.out", "w", stdout)
#define ll long long int
#define fro(i,a,n) for(ll i=a;i<n;i++)
#define pre(i,a,n) for(ll i=n-1;i>=a;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
#define fi first
#define se second
#define s_d(a) scanf("%d",&a)
#define s_lld(a) scanf("%lld",&a)
#define s_s(a) scanf("%s",a)
#define s_ch(a) scanf("%c",&a)
typedef pair<ll,ll> P;
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
const double PI = 3.1415926535897932;
const double EPS=1e-6;
const int INF=0x3f3f3f3f;
const int maxn = 2e5+100;
int lowbit(int x){return x&(-x);}
vector<ll> s;
void solve(ll n)
{ll temp=sqrt(n);for(int i=2;i<=temp;i++){while(n%i==0){n/=i;s.push_back(i);}}if(n!=1)s.push_back(n);
}
int main()
{//ios::sync_with_stdio(0);ll t;cin>>t;while(t--){s.clear();ll a;cin>>a;fro(i,0,a){ll b;cin>>b;solve(b);}sort(s.begin(),s.end());if(s.size()<2)cout<<-1<<endl;else{ll aa=s[0]*s[1];//cout<<1<<endl;cout<<aa<<endl;}}return 0;
}

更多推荐

The Factor HDU - 5428(数论)

本文发布于:2023-07-28 15:26:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1235570.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数论   Factor   HDU

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!