题解 | #最简真分数#
最简真分数
https://www.nowcoder.com/practice/1f1db273eeb745c6ac83e91ff14d2ec9
#include <stdio.h> int Is(int a,int b){ int t; if(a==b){ return 0; } if(a>b){ t=a; a=b; b=t; } while (a!=1&&a!=0) { b=b%a; t=a; a=b; b=t; } return a; } int main() { int n; int ans=0; int a[1001]={0}; scanf("%d",&n); while (n!=0) { for(int i=0;i<n;i++){ scanf("%d",&a[i]); } ans=0; for(int i=0;i<n-1;i++){ for(int j=i+1;j<n;j++){ if(Is(a[i],a[j])){ ans++; } } } printf("%d\n",ans); if(scanf("%d",&n)==EOF){ return 0; } } }