Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- //cambian de coprimo a sacar gcd neto
- int GCD(int a,int b) {
- if(a%b==0) {
- return b;
- }else {
- return GCD(b,a%b);
- }
- }
- int main() {
- int T,count=0,gcdaux,N,num;
- vector<int> nums;
- cin>>T;
- while(count<T) {
- cin>>N;
- for(int i=0;i<N;i++) {
- cin>>num;
- nums.push_back(num);
- }
- gcdaux=nums.back();
- nums.pop_back();
- for(int i=0;i<N-1;i++) {
- gcdaux=GCD(gcdaux,nums[i]);
- }
- if(gcdaux==1) cout<<N<<endl;
- else cout<<"-1"<<endl;
- nums.clear();
- count++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement