• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HaibaraAi
博客园    首页    新随笔    联系   管理    订阅  订阅

Sgu 119

119. Magic Pairs

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

 注意先%n能被n整除的ax+by那么d*ax+d*by也能因为a,b<n所以(d*ax+d*by)%n的也能被n整除,然后枚举!

“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 N, A0 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

3
1 2

Sample Output

3 
0 0
1 2
2 1
 1 #pragma comment(linker,"/STACK:102400000,102400000")
 2 #include <cstdio>
 3 #include <vector>
 4 #include <cmath>
 5 #include <queue>
 6 #include <set>
 7 #include <cstring>
 8 #include <iostream>
 9 #include <algorithm>
10 using namespace std;
11 #define INF 0x7fffffff 
12 #define mod 1000000007
13 #define ll long long
14 #define maxn 200005
15 #define pi acos(-1.0)
16 #define dis(a, b) sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y))
17 ll gcd(ll n, ll m){ return m ? gcd(m, n%m) : n; }
18 int n, m, k, c, a, b, x, y;
19 struct node{
20     int a, b;
21 }p[maxn];
22 bool cmp(node a, node b){ return (a.a < b.a || a.a == b.a&&a.b < b.b); }
23 int main(){
24     scanf("%d%d%d", &n, &a, &b);
25     a %= n; b %= n;
View Code


 


Author : Michael R. Mirzayanov
Resource : PhTL #1 Training Contests
Date : Fall 2001
posted @ 2014-02-10 05:52  HaibaraAi  阅读(155)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3