为防止广告,目前nocow只有登录用户能够创建新页面。如要创建页面请先登录/注册(新用户需要等待1个小时才能正常使用该功能)。

Sgu/119

来自NOCOW
< Sgu
跳转到: 导航, 搜索

如果AX+BY能被N整除,则dAX+dBY也能,因A,B<N,所以(dA mod N)X+(dB mod N)Y也能,把所有情况枚举完排序输出。

#include <stdio.h>
#include <algorithm>
using namespace std;
typedef struct { int a, b; } Set;
 
Set S[10001];
int N, A, B, cnt;
 
bool cmp(const Set &x, const Set &y)
{
     return (x.a < y.a || x.a == y.a && x.b < y.b); 
}
 
int main()
{
    scanf("%d %d %d", &N, &A, &B);
    A %= N; B %= N;
    int a = A, b = B;
    do {
       a = (a + A) % N;
       b = (b + B) % N;
       S[cnt].a = a;
       S[cnt].b = b;
       cnt++;
    }  while (a != A || b != B);
    sort(S, S+cnt, cmp);
    printf("%d\n", cnt);
    for (int i = 0; i < cnt; ++i)
        printf("%d %d\n", S[i].a, S[i].b); 
    return 0;
}
//From FingerSed
个人工具