您的位置:首页 > 大数据 > 人工智能

SGU Magic Pairs

2015-07-24 16:08 555 查看
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取模 那一部分都约去了。。

/*Author :usedrose  */
/*Created Time :2015/7/24 14:55:16*/
/*File Name :2.cpp*/
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <vector>
#include <string>
#include <ctime>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
#define MAXN 1110
#define OK cout << "ok" << endl;
#define o(a) cout << #a << " = " << a << endl
#define o1(a,b) cout << #a << " = " << a << "  " << #b << " = " << b << endl
using namespace std;
typedef long long LL;

set<pair<int, int > > s;
int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
cin.tie(0);
ios::sync_with_stdio(false);
int n, a, b;
cin >> n;
cin >> a >> b;
for (int i = 1;i <= n; ++ i)
s.insert(make_pair((a*i)%n, (b*i)%n));
cout << s.size() << endl;
set<pair<int, int> > ::iterator it = s.begin();
while (it != s.end()) {
cout << it->first << " " << it->second << endl;
it++;
}

return 0;
}


View Code

大牛的详细分析:
http://d.ream.at/sgu-119/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: