蓝桥杯2021
1 #include<iostream> 2 #include<vector> 3 #include<set> 4 using namespace std; 5 typedef pair<int,int> PII; 6 typedef pair<PII,int> PIII; 7 vector<PII> v; 8 set<PIII> s; 9 int x,y; 10 int gcd(int a,int b){ 11 if(b==0) return a; 12 return gcd(b,a%b); 13 } 14 int main(){ 15 cin>>x>>y; 16 17 for(int i=0;i<x;i++){ 18 for(int j=0;j<y;j++){ 19 v.push_back({i,j}); 20 } 21 } 22 23 for(int i=0;i<v.size();i++){ 24 for(int j=i+1;j<v.size();j++){ 25 int x1=v[i].first; 26 int y1=v[i].second; 27 int x2=v[j].first; 28 int y2=v[j].second; 29 int A=y1-y2,B=x2-x1,C=x1*y2-x2*y1; 30 int gcdd=gcd(gcd(A,B),C); 31 s.insert({{B/gcdd,A/gcdd},C/gcdd}); 32 } 33 } 34 35 cout<<s.size(); 36 return 0; 37 //答案40257 38 }