sgu119

来源:互联网 发布:淘宝客服怎么手机登录 编辑:程序博客网 时间:2024/05/23 17:57

题目:

119. Magic Pairs

time limit per test: 0.25 sec. 
memory limit per test: 4096 KB

“Prove that for any integer X and Y if 5X+4Y is divided by 23 than 3X+7Y is divided by 23 too.” The task is from city Olympiad in mathematics in Saratov, Russia for schoolchildren of 8-th form. 2001-2002 year. 


For given N and pair (A0, B0) find all pairs (A, B) such that for any integer X and Y if A0X+B0Y is divided by N then AX+BY is divided by N too (0<=A,B<N).

Input

Each input consists of positive integer numbers NA0 and B0 (N,A0,B0£ 10000) separated by whitespaces.

Output

Write number of pairs (A, B) to the first line of output. Write each pair on a single line in order of non-descreasing A (and B in case of equal A). Separate numbers by single space.

Sample Input

31 2

Sample Output

3 0 01 22 1

Author: Michael R. MirzayanovResource: PhTL #1 Training ContestsDate: Fall 2001题解:

由某些结论我们得知:A=(k*A0)%n, B=(k*b0)%n,然后直接排序输出即可


代码:

#include<cstdio>#include<cstdlib>#include<vector>#include<algorithm>#include<iostream>#include<iterator>using namespace std;typedef pair<int, int> pp;vector<pp> ans;int A, B, n;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;ans.push_back(make_pair(a, b));}while (a != A || b != B);printf("%d\n", ans.size());sort(ans.begin(), ans.end());vector <pp>::iterator it;for (it = ans.begin(); it != ans.end(); it++) printf("%d %d\n", it->first, it->second);return 0;}
话说用vector这种东西也不是太熟练,到网上查的。。。

话说用vector这种东西也不是太熟练,到网上查的。。。
0 0