Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. //cambian de coprimo a sacar gcd neto
  5. int GCD(int a,int b) {
  6. if(a%b==0) {
  7. return b;
  8. }else {
  9. return GCD(b,a%b);
  10. }
  11.  
  12. }
  13.  
  14. int main() {
  15. int T,count=0,gcdaux,N,num;
  16. vector<int> nums;
  17. cin>>T;
  18. while(count<T) {
  19. cin>>N;
  20. for(int i=0;i<N;i++) {
  21. cin>>num;
  22. nums.push_back(num);
  23. }
  24. gcdaux=nums.back();
  25. nums.pop_back();
  26. for(int i=0;i<N-1;i++) {
  27. gcdaux=GCD(gcdaux,nums[i]);
  28. }
  29.  
  30. if(gcdaux==1) cout<<N<<endl;
  31. else cout<<"-1"<<endl;
  32.  
  33.  
  34.  
  35. nums.clear();
  36. count++;
  37. }
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement