SGU Magic Pairs

A0x + B0y = kn

Ax + By = k'n

左差得

(A - A0)x + (B -B0)y = 0(mod n)

所以只要枚举A0, B0的倍数就行了。。

公式就是 ( (i*a)%n, (i*b)%n ), i =0, 1, ... , n-1

i*a, i*b如果大于n的话 不会影响结果, 因为对n取模 那一部分都约去了。。

 1 /*Author :usedrose  */
 2 /*Created Time :2015/7/24 14:55:16*/
 3 /*File Name :2.cpp*/
 4 #include <cstdio>
 5 #include <iostream>
 6 #include <algorithm>
 7 #include <sstream>
 8 #include <cstdlib>
 9 #include <cstring>
10 #include <climits>
11 #include <vector>
12 #include <string>
13 #include <ctime>
14 #include <cmath>
15 #include <deque>
16 #include <queue>
17 #include <stack>
18 #include <set>
19 #include <map>
20 #define INF 0x3f3f3f3f
21 #define eps 1e-8
22 #define pi acos(-1.0)
23 #define MAXN 1110
24 #define OK cout << "ok" << endl;
25 #define o(a) cout << #a << " = " << a << endl
26 #define o1(a,b) cout << #a << " = " << a << "  " << #b << " = " << b << endl
27 using namespace std;
28 typedef long long LL;
29 
30 set<pair<int, int > > s;
31 int main()
32 {
33     //freopen("data.in","r",stdin);
34     //freopen("data.out","w",stdout);
35     cin.tie(0);
36     ios::sync_with_stdio(false);
37     int n, a, b;
38     cin >> n;
39     cin >> a >> b;
40     for (int i = 1;i <= n; ++ i) 
41         s.insert(make_pair((a*i)%n, (b*i)%n));
42     cout << s.size() << endl;
43     set<pair<int, int> > ::iterator it = s.begin();
44     while (it != s.end()) {
45         cout << it->first << " " << it->second << endl;
46        it++;    
47     }
48 
49     return 0;
50 }
View Code

 

大牛的详细分析:

http://d.ream.at/sgu-119/

转载于:https://www.cnblogs.com/usedrosee/p/4673818.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值