Maruf_Hasan

maximum gcd.cpp

Oct 16th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5.  
  6. int gcd(int a,int b)
  7. {
  8. if(a%b==0)return b;
  9. else return gcd(b,a%b);
  10. }
  11. int main()
  12. {
  13. int n,i,k,j=0;
  14. scanf("%d",&n);
  15. getchar();
  16. while(n--)
  17. {
  18. int a[1000];//stringstream vector e kaj kortese na
  19. int max=1,j,num,count=0;
  20. char line[1000];
  21. gets(line);
  22. stringstream ss(line);
  23. while(ss>>num){
  24. a[count++]=num;
  25. }
  26.  
  27. for(i=0;i<count-1;i++)
  28. {
  29. for(j=i+1;j<count;j++)
  30. {
  31. k=gcd(a[i],a[j]);
  32. if(k>max)max=k;
  33. }
  34. }
  35. cout<<max<<endl;
  36. }
  37.  
  38. return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment