标签:blog io for div amp log algorithm return
欧几里得- -要分N种情况- -
#include<cstdio> #include<algorithm> using namespace std; int gcd(int x,int y){if (y==0) return x;return gcd(y,x%y);} struct node { int x,y; friend bool operator < (const node &a, const node &b) { if(a.x != b.x) return a.x < b.x; return a.y < b.y; } }ans[10030]; int main() { int n,a1,b1; scanf("%d%d%d",&n,&a1,&b1); a1=a1%n;b1=b1%n; int i=n/gcd(n,a1),j=n/gcd(n,b1); int sum=i*j/gcd(i,j); for (int i=1;i<=sum;i++) { ans[i].x=(a1*i)%n; ans[i].y=(b1*i)%n; } sort(ans+1,ans+1+sum); printf("%d\n",sum); for (int i=1;i<=sum;i++) printf("%d %d\n",ans[i].x,ans[i].y); return 0; }
标签:blog io for div amp log algorithm return
原文地址:http://www.cnblogs.com/lostwinder/p/3880826.html