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/

posted @ 2015-07-24 16:08  UsedRose  阅读(148)  评论(0编辑  收藏  举报