fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5.  
  6. int nwd(int a, int b){
  7.  
  8. while(b!= 0){
  9.  
  10. int p= a%b;
  11. a=b;
  12. b=p;
  13. }
  14. return a;
  15. }
  16.  
  17. int main() {
  18.  
  19.  
  20. ios_base::sync_with_stdio(false);
  21. cin.tie(NULL);
  22. cout.tie(0);
  23.  
  24. int n;
  25. cin >>n;
  26.  
  27.  
  28. vector<int> ted(n);
  29.  
  30. for(int i=0;i <n; i++){
  31. cin >> ted[i];
  32. }
  33.  
  34. long long wynik =0;
  35.  
  36. for(int i =0; i <n ;i++){
  37.  
  38. for(int j= i+1; j <n ;j++){
  39.  
  40. if(nwd(ted[i], ted[j])==1){
  41. wynik++;
  42. }
  43. }
  44.  
  45. }
  46.  
  47. cout << wynik << endl;
  48.  
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 5292KB
stdin
5
3 6 4 7 3
stdout
6